AT>> char s[40];
AT>> fgets (s, 40, stdin);
AT>> printf ("\n\nThis was the string you entered: %s\n", s);
NH> That will STILL give a case of the nasties if the user enters 40
NH> characters. You must make room for the terminating null.
NH> char s[41];
NH> fgets(s,40,stdin);
No. From the Borland C++ help file:
Syntax
#include
char *fgets(char *s, int n, FILE *stream);
Description
Gets a string from a stream.
fgets reads characters from stream into the string s. The function stops
reading when it reads either n - 1 characters or a newline character
whichever comes first. fgets retains the newline character at the end of s. A
null byte is appended to s to mark the end of the string.
Return Value
On success fgets returns the string pointed to by s; it returns NULL on
end-of-file or error.
See, "n-1" ... In other words, it'll read up to 39 chars.
--- PointEd 2.0
---------------
* Origin: The Tibbs' Point - Ottawa, Ontario, Canada (1:163/215.38)
|