Should I always set the last value of a char array to '\0'
?
char search_for[80];
search text here
printf("Search for: ");
scanf("%79s", search_for);
search_for[strlen(search_for) - 1] = '\0';
This is a example from a C book.
Should I always set the last value of a char array to '\0'
?
char search_for[80];
search text here
printf("Search for: ");
scanf("%79s", search_for);
search_for[strlen(search_for) - 1] = '\0';
This is a example from a C book.
When using scanf
with the %s
format it adds it for you, one huge logical error you have though is using strlen
when you're not sure that your string is null terminated.