The UNIX Forums
"Join the Network of UNIX System Users"


 
Subject: command line args
jacklefataliste
Newbie
Rank: 1



UID 194
Digest Posts 0
Credits 0
Posts 39
Reading Access 10
Registered Apr 25, 2007
Status Offline
Post at Jun 20, 2007 10:25 AM  Profile | P.M. 
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?


Top
 

 

All times are GMT, the time now is Mar 15, 2010 03:44 PM

Powered by Discuz! 5.0.0  © 2001-2006 UNIX Forums
Processed in 0.005125 second(s), 8 queries

Clear Cookies - Contact Us - UNIX Help - Archiver - WAP