Your Browser is not longer supported
Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...
{{viewport.spaceProperty.prod}}
fgets - Read in a string from a file
&pagelevel(4)&pagelevel
Definition | #include <stdio.h> char *fgets(char *s, int n, FILE *fp); fgets reads at most n-1 characters from the file with file pointer fp, stopping at the next newline (and including it) or at the end of the file. The read characters are entered by fgets into the area to which s points. |
Return val. | Pointer to the result string |
| if successful. fgets terminates the string with the null byte (\0). |
NULL pointer | if fgets has read nothing, e.g. because end of file was reached immediately or an error occurred when reading. |
Notes | You must explicitly provide the area in which fgets is to store the string read! In contrast to gets , fgets also enters a newline character (if read) into the result string. Taste K2 drücken, die Systemkommandos EOF und RESUME-PROGRAM eingeben. The following applies in the case of text files with SAM access mode and variable record length for which a maximum record length is also specified: When the specification
split=no was entered for fopen , records of maximum record length are not concatenated with the subsequent record when they are read. By default or with the specification
split=yes , when a record with maximum record length is read, it is assumed that the following record is the continuation of this record and the records are concatenated. |
Example See also | See the example of fputs gets, fopen, fopen64, puts, fputs |