I'm learning C and have made this very simple function to compare two strings. I would like to know how it can be improved:
int match(char* string1, char* string2)
{
size_t i = 0;
while (string1[i] != '\0' || string2[i] != '\0') {
if (string1[i] != string2[i]) {
return 0;
}
++i;
}
return 1;
}
I figured it will only do 2 comparisons per iteration, and 3 in the last iteration. Also, I believe it won't go beyond the end of any array because it will return before iterating beyond the null terminator.