HeadFirstC icon indicating copy to clipboard operation
HeadFirstC copied to clipboard

comment on code snippet in book

Open NieuweNils opened this issue 4 years ago • 0 comments

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?

NieuweNils avatar May 05 '20 16:05 NieuweNils