Skip to content

Commit a8d217c

Browse files
authored
Update strend.c
By starting the comparison loop from '\0', you are making the t_length variable finish too early, leaving out the last letter unchecked for equality. Try 'printf("%d", strend("my cat", "dat"));' and you'll get an output of 1.
1 parent 7f3097e commit a8d217c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

chapter_5/exercise_5_04/strend.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ int strend(char *s, char *t)
3232
size_t t_length = strlen(t);
3333

3434
// Move the s & t pointer to the end of the corresponding strings.
35-
s += s_length;
36-
t += t_length;
35+
s += s_length - 1;
36+
t += t_length - 1;
3737

3838
// Check backwards if each character from string t occurs in the corresonding
3939
// location from the string s.

0 commit comments

Comments
 (0)