The ending newline character ('\n') is not included in the string.
A null character ('\0') is automatically appended after the last character copied to str to signal the end of the C string.
Notice that gets does not behave exactly as fgets does with stdin as argument: First, the ending newline character is not included with gets while with fgets it is. And second, gets does not let you specify a limit on how many characters are to be read, so you must be careful with the size of the array pointed by str to avoid buffer overflows.
Parameters
- str
- Pointer to an array of chars where the C string is stored.
Return Value
On success, the function returns the same str parameter.If the End-of-File is encountered and no characters have been read, the contents of str remain unchanged and a null pointer is returnes.
If an error occurs, a null pointer is returned.
Use either ferror or feof to check whether an error happened or the End-of-File was reached.
Example
| 1 2 3 4 5 6 7 8 9 10 11 |
|
See also
| fgets | Get string from stream (function) |
| getchar | Get character from stdin (function) |
| scanf | Read formatted data from stdin (function) |
