Passing command arguments in C -


i need pass in 3 file names , integer arguments main function.

example command:

% gcc lab4.c infile1.txt infile2.txt output.txt 0 

int main(int argc, char *argv[]) 

the file names can used needed argv[1] etc...

the first 3 no problem how change formatting accommodate integer?

using emacs if makes difference

you can integer way:

int i=atoi(argv[4]); printf("%d\n",i); 

however, not forget test if argv[4] key defined:

if(argc<=4)   return exit_failure;  int i=atoi(argv[4]); printf("%d\n",i); 

Comments

Popular posts from this blog

shopping cart - Page redirect not working PHP -

php - How to modify a menu to show sub-menus -

python - Installing PyDev in eclipse is failed -