I don't understand this function called "streql" (it tests if 2 strings are equal, and it returns 1 if they are, and 0 if not...)
Here is the code, in C:
#include
int streql (char *str1, char *str2)
{
while ((*str1 == *str2) && (*str1))
{
str1++;
str2++;
}
return ((*str1 == NULL) && (*str2 == NULL));
}
void main (void)
{
printf("Testing Abc si Abc %d\n", streql("Abc", "Abc"));
printf("Testing abc si Abc %d\n", streql("abc", "Abc"));
printf("Testing abcd si abc %d\n", streql("abcd", "abc"));
}
Can you explain me what is the logic of what is written in the "while", and what is the logic of what is written inside the "return"?
2007-03-03
10:41:55
·
3 answers
·
asked by
Anonymous