scanf not to exceed buffer overrun
问题 I have a buffer and I don't want the user to enter more characters than the buffer can hold (to avoid a buffer overrun). I am using scanf and have done like this: char buffer[30] = {'\0'}; scanf("%30s", buffer); However, I know I am protected if the user enters more than 30. However, if the user enters more than 30, will the buffer be null terminated? 回答1: scanf() with a "%s" conversion specifier adds a terminating null character to the buffer. But , you're asking for 30 characters, which