TristinColby
asked on
printing arguments from commandline prints garbage.
can someone tell me what is wrong with this. I get garbage when I print the arguments.
Calling it as below gives me:
argv[0] is I
argv[1] is Ö
argv[2] is U
argv[3] is _
argv[4] is ä
argv[5] is é
testapp.exe one two three four five
int main(int argc, char **argv) {
int q;
for(q=0;q<=argc;q++) {
printf("argv[%d] is %s\n",q,argv[q]);
}
return 0;
}
Calling it as below gives me:
argv[0] is I
argv[1] is Ö
argv[2] is U
argv[3] is _
argv[4] is ä
argv[5] is é
testapp.exe one two three four five
int main(int argc, char **argv) {
int q;
for(q=0;q<=argc;q++) {
printf("argv[%d] is %s\n",q,argv[q]);
}
return 0;
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You could try:
printf("argv[%d] is %ls\n",q,argv[q]);
Paul
printf("argv[%d] is %ls\n",q,argv[q]);
Paul
int q;
for(q=0;q<argc;q++) { /* NO <=! */
printf("argv[%d] is %s\n",q,argv[q]);
Indices are zero based.