Programming :: No While Loop Is AllowedThe Lecturer's Tip Was To Treat "-" As Negative And Not Hyphen?
Mar 25, 2010
I have a assignment relating to barcode reading.Let say i have to enter the 13 digit barcode with hyphen e.g "Enter barcode:123-46574-48847" using scanf.Once thats done how do i extract the values without the hyphene.g using printf "1234657448847". No arrays No strings and No function is allowed.No while loop is allowedThe lecturer's tip was to treat "-" as negative and not hyphen.
View 4 Replies
ADVERTISEMENT
Mar 4, 2010
I am having trouble with the code below, I'm trying to check if a variable holding a character is a hyphen.
Code:
#!/bin/bash
$char="-"
if (( "$char" == "-" )); then
[code]....
View 3 Replies
View Related
Jul 19, 2011
I'm trying to create an array with variable including hyphenbut ksh refuses the first element
set -A allArgs
set +A allArgs ${allArgs[@]} -all
set +A allArgs ${allArgs[@]} -date
[code]...
View 5 Replies
View Related
May 15, 2011
How can i get bc to subtract negative numbers?
View 10 Replies
View Related
Oct 26, 2010
I need to convert an integer to a byte array of size 2 and vice versa. The code shown below works well for positive values but not for negative values. Also, using an array of size four makes the conversion works. However, I am limited to an array of size 2.
View 5 Replies
View Related
Mar 9, 2011
I am trying to grep multiple numbers from file, grep does have the -f option for that.
Code: grep -f <`seq 500 520` /etc/passwd I know this could be done with
Code: for i in `seq 500 520`; do grep "$i" /etc/passwd; done But my question is fare more behind this example. It is possible to redirect one command output which will be treat as a content of file for another command ?
View 2 Replies
View Related
Mar 31, 2011
I need to rename the resulted searched files from a loopI have the following code:
find . -name DOC* | while read i
do
find $i -type f -name '*.txt'
done
basically, I am searching for all txt files inside any folder starting with DOC name.this code is working fine with me.I need to rename those .txt files to .txtOLDOS: Ubuntu 10.4Bash shell
View 10 Replies
View Related
Feb 9, 2011
i can not figure out why my program does not terminate if i type n when i read loop unless it is the last if statement in my program ?
while [ "$loop" = y ] ; do
echo "what does baket mean: " ; read word
if [ "$word" = why ]
[code]....
View 3 Replies
View Related
Oct 3, 2010
Here is my code
Code:
I just cant seem to understand loops. i havent put the loop in yet but what i would like is the user only to have 3 tries at guessing number then exit if wrong or it says "correct if right" tbh i dont even know if the above code is correct. i have tried several ways and position of the loops but each time is comes out wrong
View 7 Replies
View Related
Mar 25, 2011
I have a directory file capturing script, the variable is fine with in the loop but gone after the loop is done:
Code:
DIR="/usb/sdb1/media/music/"
i=1
[code]...
View 9 Replies
View Related
Apr 24, 2010
I am about to move my scripts to the next generation level, so I need some help I am stuck in varying my variable names in a loop. For example:
for user in ben dorothy mike pat
do
[ -r /home/$user ] && let "$user"check=1 || let "$user"check=0
[code]...
View 1 Replies
View Related
Jun 28, 2010
I am trying to do some shell programs. I tried some sites regarding the while loop, they give the structure as:
Code:
while [ n1 -lt 500 ]
do
echo $((n1+100))
done
But the below code also worked for me:
Code:
while ((n1 > 500))
do
echo $((n1+100))
done
By using (( )) I could use while, for. But the documentations didnt follow this way. I mainly use this for datastructure programming.
View 4 Replies
View Related
Aug 1, 2010
In the code segment below is a for loop I am having some considerable difficulty with. It just keeps iterating endlessly and totally ignores the 70 times limit specified. I can't ever remember having this problem before and am absolutely Clueless.
Code:
for ( x = 0; x < 70; x++ )
{
fputs ("CSN00", target);
fprintf (target, "%d", userid);
[Code].....
View 14 Replies
View Related
Nov 3, 2010
I've got a 'nested' for loop which has a grep in it, if the grep fails there's no output - however the error code is still $0 and the second for loop is still entered, there's also a grep in the second for loop.I guess ultimately what i need to know is whether there's a way of making grep generate an error code. when no results are found?
View 14 Replies
View Related
Apr 23, 2011
I want to loop through the records in the below file (homedir.temp)
/home/user1
/home/user2
/home/user3
I want to do the following activities with each record1. du -s - to get the total usage for that directory (my variable name is SIZE)2. divide SIZE by du -c for /home to get the percentage of usage. (my variable name is PER)3. write the directory, SIZE, PER to a filePROBLEMI am using the below for loop: for record in homedir.tempthe mentioned activitiesdonehe above is not looping through the records. It does the first record perfectly and exits the loop.
View 14 Replies
View Related
Apr 25, 2010
ITT and am just lurning about scripting and need to read a file and output the file to the screen. We need to do this with a while loop.
View 5 Replies
View Related
Mar 7, 2010
When I deal with an array in a function I con not access to the content of array in a for loop, but out of a for loop I can access to them! for example
[code]...
In a function when I send as parameter, in a for loop it prints the content of array and out of a for loop it prints the address of arr[i]
View 5 Replies
View Related
Nov 18, 2010
I'm writing a mass snmp toner check which polls any toners available to be snmp polled, however when using a loop statement I get the results on different lines; which sounds good, however the tool I use to check with (nagios) ignores the new lines.
Is there any way I can get the output on one line? Also, I need to raise a fault if any of the toners are below a specific level (with nagios you raise faults with the exit code) - any way I can do this without exiting the loop. Code below with bits and bobs commented out.
Code:
check_ink_levels ()
{
for ID in $INKS
do
[Code].....
View 10 Replies
View Related
Jun 1, 2010
#!/usr/bin/perl -w
use strict;
my @files = `ls -1`;
[code]...
View 2 Replies
View Related
Jun 29, 2011
I have a 50 file name NSSAVE0001.vtk to NSSAVE0050.vtk.Do I have to manually type individually command to open each file or can I have a loop to open file?
View 3 Replies
View Related
May 11, 2009
so far I have this
list = open('list.txt')
for x in list:
list.read(x)
View 3 Replies
View Related
Mar 1, 2010
I need to pass a large number of arguments to a function which takes variable number of arguments, such as gtk_list_store_new. But it doesn't look nice if i write something like gtk_list_store_new(NUM,TYPE_A,TYPE_B,TYPE_C,...,TYPE_OMEGA); because of large number of arguments. And, it will be a trouble to change number of columns because of need to manually change arguments to large number of such functions. So, how can i pass all the arguments to a function using a loop? Something like
Code:
for(i=0;i<NUM;i++)
{
push_arg(args[i]);
}
call_function(func);
?
Of course, i could just use asm code for this, but is there a portable way of doing so?
P.S. i mean C language.
View 2 Replies
View Related
May 26, 2011
I have images in jpg format
Code:
CIMG0100.jpg
...
...
CIMG0131.jpg
I used imagemagick to convert the files to gif with the following command
Code:
for i in {100..131}; do convert CIMG0$i.jpg CIMG0$i.gif; done # works
This worked like expected, but when afterwards I wanted to scale the images
Code:
for i in {100..131}; do convert -scale 25% CIMG00$i.gif CIMG00$i_scaled.gif; done # works not it seems the system is working for about half a minute, but I get no output. The single command
Code:
convert -scale 25% CIMG100.gif CIMG100_scaled.gif # works
works as expected and gives me a scaled image. What does the convert command do in the second case? is the for-loop wrong?
View 2 Replies
View Related
Aug 13, 2010
I'm learning c but then when i tried looping as i follow a tutorial, the numbers are wierd that it seems not right..
This is the example.
Quote:
When i run it, it outputs this.
Quote:
why?
View 2 Replies
View Related
Jul 9, 2010
I hade created a file with following text entries.
content of fileitems.txt
kdeaccessibility-4.4.92
kdeadmin-4.4.92
kdeartwork-4.4.92
kdebase-4.4.92
How do I read the file one line at a time and so its ready to do something with that line.
View 3 Replies
View Related
Apr 19, 2011
hint me why and how to execute the below for loop, the way i am trying to?
[bkcreddy17@local:~]$ cat -n test
1 date
2 ls -l
[code]...
View 14 Replies
View Related
Oct 10, 2010
my issue is that the when i put in the correct input its going into the loop like i put in incorrect input and wont break out of the loop even with the correct input entered
Code:
import java.util.*;
import javax.swing.*;
[code]...
View 3 Replies
View Related
Nov 25, 2010
I've got a loop which is able to echo out how complete a process is after each loop (e.g says 25% if the loop has 4 elements and has run once through). Is there any way I can print characters, perhaps a progress bar? I was thinking of using the percentage as a count or something and using.
Code:
I got told off for including code from work here.
View 14 Replies
View Related
Jun 7, 2010
The script that Iam trying to write is running a for loop and reading line by line from a text file. inside this for loop i would like to execute update SQL statement .
a pesudo code is
Quote:
`$ISQL -U $username -P $Password -D $Dbname -I $INTERFACE <<QRY
for id in $idlist #idlist iam reading from a file
[code]...
View 8 Replies
View Related
Jan 1, 2011
I have a file like below:
PU12829,24869;PD15733,24869;PD15733,19785;PD12829,19785;PD12829,24869;
PU4599,20915;PD9924,20915;PD9924,18898;PD4599,18898;PD4599,20915;
PU12829,24869;PD15733,24869;PD15733,19785;PD12829,19785;PD12829,24869;
PU4599,20915;PD9924,20915;PD9924,18898;PD4599,18898;PD4599,20915;
PU1723,3423; #this line is ignored to short
[Code]...
What I'm trying to do is while true, cut each line from file that begins with PU and thats longer than 12 characters and write to a increasing numbered file for each line. Stating with object1 etc.
View 14 Replies
View Related