Skip to content

Commit 9e36a2a

Browse files
authored
Merge pull request #34 from metalbuild-mnbv/main
Update strindex.c
2 parents c489b43 + e892a13 commit 9e36a2a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

chapter_5/exercise_5_06/strindex.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ int strindex(char *s, char *t);
55
int main(void)
66
{
77
char s[] = "this is first string";
8-
char t[] = "first";
8+
char t[] = "this";
99

1010
printf("%d", strindex(s, t));
1111

@@ -18,10 +18,8 @@ int strindex(char *s, char *t)
1818
char *second;
1919
int pos = 0;
2020

21-
while (*s++ != '\0')
21+
while (*s != '\0')
2222
{
23-
++pos;
24-
2523
if (*s == *t)
2624
{
2725
first = s;
@@ -33,6 +31,8 @@ int strindex(char *s, char *t)
3331
return pos;
3432
}
3533
}
34+
pos++;
35+
s++;
3636
}
3737

3838
return -1;

0 commit comments

Comments
 (0)