aboutsummaryrefslogtreecommitdiff
path: root/ch4/4-01_strrindex.c
diff options
context:
space:
mode:
authorzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
committerzlg <zlg@zlg.space>2016-06-16 10:15:33 -0700
commitf8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7 (patch)
treee37b327d7f93435e93a57427600d2b91fbb0cd87 /ch4/4-01_strrindex.c
parentSolve Exercise 7-2: Format arbitrary input (diff)
downloadknr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.gz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.bz2
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.tar.xz
knr-f8d9ff23eb8d3e3286ff5cf4d5f9493532991bb7.zip
The massive astyle sweep!
Code style should be consistent now. All future commits will be run through astyle or they will be amended.
Diffstat (limited to 'ch4/4-01_strrindex.c')
-rw-r--r--ch4/4-01_strrindex.c6
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);