I was reading about header string.h
functions in link and I came across with a strings function (very useful after all), such as strcmp(string1, string2)
.
Depending on the first character that does not match, that is, it is different, string1 has a "value" greater or less than string2
. I was stuck with this, so I decided to test in 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, a value of 0 is returned (as specified in link ). However, I could not understand why other values. The value returned is the difference of the characters according to the ASCII table? Otherwise, how does value assignment work?