Doubt in strcmp

2

I'm in doubt on a line of code:

if(strcmp(novo->nome,aux->nome)>=0)

How does your comparison work? Being that the name is a char!

    
asked by anonymous 09.06.2014 / 18:42

1 answer

2

The strcmp method tests the equality of the Strings.

  • Returns a negative number if string1 is less than string2;
  • Returns zero if the two strings are equal;
  • Returns a positive number if string1 is greater than string2.
  • The method declaration is as follows:

    int strcmp ( const char * str1, const char * str2 );
    

    So, it returns an integer.

    So, in your code, it will go into if's scope when novo->nome is equal to or greater than aux->nome

        
    09.06.2014 / 19:01