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?