--- In [email protected], "David Hamill" <[EMAIL PROTECTED]> wrote: > > > If you malloc() 42 bytes then tell > > fgets() to read 42 bytes, it is impossible > > to overflow the buffer, so is very safe. > > In the case of fgets(), a terminating '\0' is helpfully > included in the count, unlike most string functions where a > string of n chars needs storage of n+1 chars. This means > that fgets(buffer, n, stream) will only get n-1 characters, > so there's the possibility of an out-by-one error. But at > least it's safe.
And don't forget that fgets() adds a '\n' to the end of the string if there are n-2 or less characters in the input. Actually I think what the OP was saying was that he allocates an array of say N ints and reads them from the file, stopping if there are more than N. Hence the use of fscanf(). John
