From f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7 Mon Sep 17 00:00:00 2001 From: zlg Date: Thu, 16 Jun 2016 10:15:33 -0700 Subject: The massive astyle sweep! Code style should be consistent now. All future commits will be run through astyle or they will be amended. --- ch4/4-01_strrindex.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'ch4/4-01_strrindex.c') 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); -- cgit v1.2.3-54-g00ecf ref='/knr/commit/ch1/1-16_longest-line.c?id=c5ae86e5e146c2107aaf6c04a01314f83b1b3ffd&follow=1'>commitdiff
path: root/ch1/1-16_longest-line.c (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2013-06-22Solve Exercise 4-7: ungets()zlg2-2/+278