Link to home
Start Free TrialLog in
Avatar of TristinColby
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;
}

ASKER CERTIFIED SOLUTION
Avatar of jkr
jkr
Flag of Germany image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, make that loop

        int q;
        for(q=0;q<argc;q++) { /* NO <=! */
                printf("argv[%d] is %s\n",q,argv[q]);

Indices are zero based.
You could try:

               printf("argv[%d] is %ls\n",q,argv[q]);

Paul