fgets() Read a String from Stream
#include <stdio.h>
char *fgets(string,n,stream);
char *string; Storage location
int n; Number of characters stored
FILE *stream; Pointer to file structure
fgets() reads characters from 'stream' and stores them in 'string'.
fgets() stops reading at the first new-line character (in which case
the new-line itself will be stored in 'stream'); at the end of the
stream; or when 'n'-1 characters have been read, whichever comes
first. A null character ('\0') is appended at the end of 'stream'.
Returns: The resultant string. A NULL value is returned if
there's an error or end-of-file condition. Because EOF
is a legitimate value that may be read from 'stream', use
ferror() or feor() to determine whether an error or
end-of-file condition exists.
Notes: fgets() is similar to gets(), but gets() replaces the
new-line character with the null character.
-------------------------------- Example ---------------------------------
This example gets a line of input from 'stream'.
#include <stdio.h>
char string[50], *newstring;
FILE *stream;
main()
{
if ((stream = fopoen("new.dta","r+")) != NULL) {
newstring = fgets(string,50,stream);
}
}
Seealso:
This page last updated on Fri Nov 30 10:48:32 MSK 2001
Copyright © 1992-2001, Vitaly Filatov, Moscow, Russia
Webmaster