Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

comment on code snippet in book #3

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

comment on code snippet in book #3

wants to merge 1 commit into from

Conversation

NieuweNils
Copy link

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?

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?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant