From a8d217c60428493b05706f93bc58513e5f3d81d0 Mon Sep 17 00:00:00 2001 From: sadeem_albir <142955101+sadeem-albir@users.noreply.github.com> Date: Thu, 21 Mar 2024 10:45:56 +0300 Subject: [PATCH] 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. --- chapter_5/exercise_5_04/strend.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/chapter_5/exercise_5_04/strend.c b/chapter_5/exercise_5_04/strend.c index 53673be..9094d86 100644 --- a/chapter_5/exercise_5_04/strend.c +++ b/chapter_5/exercise_5_04/strend.c @@ -32,8 +32,8 @@ int strend(char *s, char *t) size_t t_length = strlen(t); // Move the s & t pointer to the end of the corresponding strings. - s += s_length; - t += t_length; + s += s_length - 1; + t += t_length - 1; // Check backwards if each character from string t occurs in the corresonding // location from the string s.