Using argv[1] in C program

Top Page
Attachments:
Message as email
+ (text/plain)
Delete this message
Reply to this message
Author: David Koopman
Date:  
To: plug-discuss
Subject: Using argv[1] in C program
I have a simple C question, hoping someone can help.

I was doing this on one machine:

let i=0; while [ $i -lt 1 ]; do
# some action
usleep 200000
done

I then moved to a different machine and "usleep" was not a binary on the
new machine. So, I created a quick c file:

shell> vi usleep200000.c

int main() {
usleep(200000);
}


shell> make usleep200000

Now I can accomplish this same thing:

let i=0; while [ $i -lt 1 ]; do
# some action
./usleep200000
done


So, now for my question....

How do I change my C program to take the milliseconds to sleep from the
command line? I think it's something like this:

int main(argc, argv) {
usleep(argv[1]);
}

But that doesn't work, it says:

cc     usleep.c   -o usleep
usleep.c: In function `main':
usleep.c:2: error: subscripted value is neither array nor pointer
make: *** [usleep] Error 1



help?

---------------------------------------------------
PLUG-discuss mailing list -
To subscribe, unsubscribe, or to change you mail settings:
http://lists.PLUG.phoenix.az.us/mailman/listinfo/plug-discuss