Problems with char array and atoi function

Hello all

I'm having a small problem, who tends to get bigger and bigger, as I cannot go past it.

The situation is as follows. I have a char array like this one:

char* row1[]={"Mada","666","10"};

What I want is to convert the numbers (666,10), who are now represented as strings, into integers, because I have some comparisons to do, and if I compare strings, I get that "10"<"9". And I want it to be the opposite.

I searched over the internet, including this forum, but it doesn't seem to work. The atoi function doesn't do anything.

1
2
int v;
v=atoi(row1[2]);


leaves the variable "v" untouched, and I don't understand why.

What am I missing here?

closed account (z05DSL3A)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include<iostream>
#include <stdlib.h>

int main()
{
    char* row1[]={"Mada","666","10"};

    for(int i = 0; i < 3; ++i)
    {
        int v;
        v = atoi( row1[i] );
    
        std::cout << "The input " << row1[i] << " results in " 
                  << v << " from atoi()." << std::endl;
    }
    return 0;
}

output:
The input Mada results in 0 from atoi().
The input 666 results in 666 from atoi().
The input 10 results in 10 from atoi().


Do you get anything different?
Topic archived. No new replies allowed.