0

I'm trying to verify if argv[1] it's bigger than argv[2]. I noticed I can't directly do it since argv is a char. But no ideea about how I could transform it into a int. There you have my code. Thanks in advance!

int main(int argc, char **argv)
{
    if(argv[1] > argv[2])
        printf("it's superior");
    return (0);
}
Asez
  • 159
  • 1
  • 3
  • 13
  • 1
    What are the possible arguments you're trying to check, are these numbers? Then you need to convert string to an integer. One possible choice is to use `atoi()` – Sudheesh Singanamalla Dec 20 '17 at 10:12
  • 3
    don't use `atoi` if you want reliability – Jean-François Fabre Dec 20 '17 at 10:12
  • Yep, these are 2 numbers. – Asez Dec 20 '17 at 10:17
  • The `argv[x]` arguments are ALWAYS (as the param declaration indicates) C strings (memory buffer 0 terminated). You cannot compare C strings as it were numbers. You have to use strcmp or convert the strings in numbers using one of the opportune conversion functions (atoi, strtol, strtod ... and so on). – Sir Jo Black Dec 20 '17 at 10:18
  • Ok. Can you please give me an example about using atoi with argv? I've seen some but with only a value. – Asez Dec 20 '17 at 10:24

0 Answers0