Argc/Argv C Problems
Posted
by Salman
on Stack Overflow
See other posts from Stack Overflow
or by Salman
Published on 2010-05-07T21:11:17Z
Indexed on
2010/05/07
21:18 UTC
Read the original article
Hit count: 258
c
Hey all,
If I have the following code:
main(int argc, char *argv[]){
char serveradd[20];
strcpy(serveradd, argv[1]);
int port = atoi(argv[2]);
printf("%s %d \n", serveradd, port);
The first two arguments to the command line are printed. However, if I do this:
char serveradd[20];
strcpy(serveradd, argv[1]);
int port = atoi(argv[2]);
char versionnum[1];
strcpy(versionnum, argv[3]);
printf("%s %d %s \n", serveradd, port, versionnum);`
The first argument (serveradd) does not print out to the screen and is not being stored... Why is this happening and how can I fix it? Thanks!
© Stack Overflow or respective owner