HeadFirstC
HeadFirstC copied to clipboard
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?