What i would like to know is how the fgets function ends the string. does it just stop, or is it automatically null terminated? i. e. for the first line of my output would s[13] = 0? code:. If you type more than four characters then the extra characters and the null terminator will be written outside the end of the array, overwriting memory not belonging to the array. this is a buffer overflow. c does not prevent you from clobbering memory you don’t own. this results in undefined behavior. your program could do anything—it could. The strlen function computes the length of a string by determining the number of characters that precede the terminating null character. a problem occurs if the first character read from the input by fgets happens to be a null character. this may occur, for example, if a binary data file is read by does fgets add null terminator the fgets call [ lai 2006 ]. A newline character makes fgets stop reading, but it is considered a valid character by the function and included in the string copied to str. a terminating null character (‘
