0

I'm passing 4 integers to my program which I then want to convert to a string.

./exercise 1 10 100 1000     

However the argv actually has a length of 5 and I don't understand where the fifth value comes from. When I debug the program it looks like the first entry is a '/'.

When I use

atoc

to convert the strings to an integer this '/' causes trouble and the i get a 0 as a first number. However when I access argv directly I have no problems

int main(int argc, char *argv[]) {
    for (int i = 0; i < argc; i++) {
        int n = atoi(argv[i]);
        cout<<n;
    }
}
// prints 0 1 10 100 1000;


int main(int argc, char *argv[]) {
    for (int i = 0; i < argc; i++) {
        cout<<argv[i];
    }
}

// prints 1 10 100 1000;
JangoCG
  • 823
  • 10
  • 23

0 Answers0