![]() |
compile program with command line arguments
Hi,
I have a program which is hard coded, I need to enter a value(n2 in the below code) in the program, and the program processes the file according to the value n2. how I compile now is as follows: cc -o test testprog.c ./test [filename] :
if((data[0]=='8')&&(data[1]=='2'))What I need to do is, modify the program in such a way that, the value n2 can be given as an argument at command line. Can anyone please help me with this? thanx Squirrel |
i dont do C but can you just ask for user input and use scanf() to get it?? and the code you posted, is that just a snip of the total code? cause you need some more stuff for it to compile right.
|
Yes, It is the snip of the total code.
Iam new to programing and not knowing how to modify. |
Here is the full code:
:
#include "check_2ndkj.h" |
:
main(int argc,char *argv[]) |
:
sscanf(argv[1],"%d",&n2); |
Now, Info, I can't believe you recommend that schlocky code. What if the user doesn't put a number there?
|
Sorry for that, Dawei.
I'd be more careful while giving advice next time. :
if(sscanf(argv[1],"%d",&n2)!=1) |
LOL, attaboy ;) .
|
Wat do I need to add or change at the IF loop of n2 ?? Can u please explain me a bit more clearly?? Sorry for the trouble!!
|
| All times are GMT -5. The time now is 8:05 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC