c++ argv[1] something strange

80 views Asked by At

I got strange problem parsing C++ arguments from argv[]. Here is some sample of code:

int main(int argc, char **argv) {
    for (int i=0; i <argc; i++)
        printf("argv[%d] = %s|\n", i, argv[i]);
    return 0;
};

When I run this program like this:

./myprogram --aaa-a --bbb-b --ccc-c

the result I get is like:

argv[0] = myprogram|
argv[1] = --aaa-a --bbb-b|
argv[2] = --ccc-c

but when I try:

./myprogram --aaa-a  --bbb-b --ccc-c

with additional space between aa and bb, I got:

argv[0] = myprogram|
argv[1] = --aaa-a|
argv[2] =  --bbb-b|
argv[3] = --ccc-c|

Does anyone can give me a clue what is happening here?

1

There are 1 answers

1
dlask On

For some reason you have a non-breakable space (or any character that's displayed as space) between --aaa-a and --bbb-b. Remove the whole command line and write it again from scratch.