2
I was reading about some of the functions of header string.h in http://www.cplusplus.com/reference/cstring/ and I came across some comparison functions between strings (useful after all), such as, for example, strcmp(string1, string2).
Depending on the first character that does not match, that is, it is different, string1 has a "value" higher or lower than the string2. I was blinded by this, so I decided to test this code:
#include <stdio.h>
#include <string.h>
int main (void)
{
char teste[10];
char teste2[10];
printf("teste: ");
scanf("%9[^\n]", teste);
printf("teste2: ");
scanf(" %9[^\n]", teste2);
printf("%d", strcmp(teste, teste2));
return 0;
}
When they are equal, the value 0 is returned (as specified in http://www.cplusplus.com/reference/cstring/strcmp/). However, I could not understand why of other values. Is the returned value the difference of the characters according to the ASCII table? Otherwise, how the value assignment works?