command line args
command line args
my program usage takes the form for example;
$ theapp 2 "one or more words"
i.e. 3 command line arguments; application name, an integer, some text
my code includes the following 4 lines:
int aninteger;
char words[80];
sscanf(argv[1], "%d", &aninteger);
sscanf(argv[2], "%s", &message);
based on th example execution shown above this code results in th following assignments:
aninterger = 2 /* correct and as i thought*/
message = one /* not as i thought or intended*/
i thought when i printed out the value of message i would get:
one or more words
but instead i get:
one
i have done a test and the use of the " " marks seems to make "one or more words" be seen as a single argument. if i don't use the " " marks it sees every word as another argument.
so even though the program sees "one or more words" as a single argument, sscanf is not reading it properly. how can i overcome this problem?
|