diff options
Diffstat (limited to '')
-rw-r--r-- | ch4/4-01_strrindex.c | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/ch4/4-01_strrindex.c b/ch4/4-01_strrindex.c index b6400c4..7818743 100644 --- a/ch4/4-01_strrindex.c +++ b/ch4/4-01_strrindex.c @@ -30,8 +30,7 @@ void reverse(char s[]) { int c, i, j; - - for (i = 0, j = strlen(s)-1; i < j; i++, j--) { + for (i = 0, j = strlen(s) - 1; i < j; i++, j--) { c = s[i]; s[i] = s[j]; s[j] = c; @@ -40,7 +39,6 @@ void reverse(char s[]) { int strindex(char s[], char t[]) { int i, j, k; - for (i = 0; s[i] != '\0'; i++) { for (j = i, k = 0; t[k] != '\0' && s[j] == t[k]; j++, k++) { } @@ -63,7 +61,6 @@ int strrindex(char s[], char t[]) { int o = strindex(s, t) + strlen(t); reverse(s); reverse(t); - // Be sure to return the correct offset with some math :3 return (strlen(s) - o); } @@ -73,7 +70,6 @@ int main() { char needle[MAXLINE] = "ned"; int pos = strrindex(haystack, needle); int i = 0; - /* This is mostly just to provide a handy visual aid */ printf("The phrase %s's rightmost occurrence is %d:\n", needle, pos); printf("%s\n", haystack); |