| Summary | |
#include <stdio.h>
char *fgets (
char *string, /* string to write to */
int n, /* length of string */
FILE *stream); /* file stream to read from */
|
| Description | | The fgets function reads a string from the input stream and stores it in string. Characters are read from the current stream position... - ...up to and including the first new-line ('\n'),
- ...up to the end of the stream,
- ...until the number of characters read is equal to n-1,
whichever comes first. A null character ('\0') is appended to string. The fgets function is in the RL-FlashFS library. The prototype is defined in stdio.h. |
| Return Value | | The fgets function returns string if successful. NULL is returned to indicate an error or end-of-file condition. Use the feof or ferror functions to distinguish an error from end-of-file. |
| See Also | | feof, ferror, fgetc, fputs |
| Example | |
#include <rtl.h>
#include <stdio.h>
void tst_fgets (void) {
FILE *fin;
char line[80];
fin = fopen ("Test.txt","r");
if (fin == NULL) {
printf ("File not found!\n");
}
else {
while (fgets (line, sizeof (line), fin) != NULL) {
puts (line);
}
fclose (fin);
}
}
|