-
-
Save Xjs/7649068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int compare_some_strings (char *a, char *b) | |
// compare some strings, return -1 if equal, otherwise the position of the first difference. | |
{ | |
int i; | |
for (i = 0; a[i] != 0 && b[i] != 0; i++) | |
if (a[i] != b[i]) | |
return i; | |
// wenn wir hier angekommen sind, sind sie bis zum Punkt i gleich | |
if (a[i] == 0 && b[i] == 0) // sie sind ganz gleich | |
return -1; | |
else // der eine ist länger als der andere, aber bis dahin sind sie gleich. | |
return i; | |
} | |
int main(void) | |
{ | |
return compare_some_strings("foo", "fobar"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment