How to receive a arg from command line in C

Posted by 115599yy on Stack Overflow See other posts from Stack Overflow or by 115599yy
Published on 2010-06-16T12:39:08Z Indexed on 2010/06/16 12:42 UTC
Read the original article Hit count: 185

Filed under:

Hi everyone:

I want to write a program to receive a argument from command line. It's like a kind of atof().

There my program goes:

  9     char s[] = "3.1415e-4";
 10     if (argc == 1) {
 11         printf("%e\n",atof(s));
 12     }
 13     else if (argc == 2) {
 14         //strcpy(s, argv[1]);
 15         printf("%e\n",atof(argv[1]));
 16     }

1.should I just use argv[1] for the string to pass to my atof(), or, put it into s[]?

2.If I'd better put it in s[], is there some build-in function to do this "put" work? maybe some function like strcpy()??

thanks.

© Stack Overflow or respective owner

Related posts about c