Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <stdio.h>
    char *fgets( char *buf, int n, FILE *fp );
    #include <stdio.h>
    #include <wchar.h>
    wchar_t *fgetws( wchar_t *buf, int n, FILE *fp );

Description:
    The fgets function gets a string of characters from the file designated
    by fp and stores them in the array pointed to by buf.  The fgets
    function stops reading characters when end-of-file is reached, or when a
    newline character is read, or when n-1 characters have been read,
    whichever comes first.  The new-line character is not discarded.  A null
    character is placed immediately after the last character read into the
    array.

    The fgetws function is identical to fgets except that it gets a string
    of multibyte characters (if present) from the input stream pointed to by
    fp, converts them to wide characters, and stores them in the
    wide-character array pointed to by buf.  In this case, n specifies the
    number of wide characters, less one, to be read.

    A common programming error is to assume the presence of a new-line
    character in every string that is read into the array.  A new-line
    character will not be present when more than n-1 characters occur before
    the new-line.  Also, a new-line character may not appear as the last
    character in a file, just before end-of-file.

    The  gets function is similar to fgets except that it operates with
    stdin, it has no size argument, and it replaces a newline character with
    the null character.

Returns:
    The fgets function returns buf if successful.  NULL is returned if
    end-of-file is encountered, or a read error occurs.  When an error has
    occurred,  errno contains a value indicating the type of error that has
    been detected.

Example:
    #include <stdio.h>

    void main()
      {
        FILE *fp;
        char buffer[80];

        fp = fopen( "file", "r" );
        if( fp != NULL ) {
          while( fgets( buffer, 80, fp ) != NULL )
            fputs( buffer, stdout );
          fclose( fp );
        }
      }

Classification:
    fgets is ANSI, fgetws is ANSI

Systems:
     fgets - All, Netware

    fgetws - All

See Also:
    fgetc, fgetchar, fopen, getc, getchar, gets, ungetc

See Also:

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson