From 3527c9ba72590e4b8d2eb454aa8299828078d2a8 Mon Sep 17 00:00:00 2001 From: NieuweNils <42936767+NieuweNils@users.noreply.github.com> Date: Tue, 5 May 2020 18:31:31 +0200 Subject: [PATCH] comment on code snippet in book Hi David! I am working through your (so far great) book on C (Head First C), and spotted a peculiarity in the code: in section 2.5, under "It's time for a code review", the code states: int main() { char search_for[80]; printf("Search for: "); scanf("%79s", search_for); search_for[strlen(search_for)-1] = '\0'; find_track(search_for); return 0; } where search_for[strlen(search_for)-1] = '\0' replaces the last inputted character. should it be search_for[strlen(search_for)] = '\0'; instead? --- chapter2.5/Page 47/code.c | 1 + 1 file changed, 1 insertion(+) diff --git a/chapter2.5/Page 47/code.c b/chapter2.5/Page 47/code.c index 1768057..83549c1 100644 --- a/chapter2.5/Page 47/code.c +++ b/chapter2.5/Page 47/code.c @@ -22,6 +22,7 @@ find_track(search_for); return 0; } + int main() { char search_for[80];