Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>fgets() read a string from stream</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 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.  Also,
                    gets() reads only from stdin.

   -------------------------------- Example ---------------------------------

    This example gets a line of input from 'stream'.

           #include <stdio.h>

           char string[50], *newstring;
           FILE *stream;

           main()
           {
                if ((stream = fopen("new.dta","r+")) != NULL)  {
                    newstring = fgets(string,50,stream);
               }
           }



See Also: fgets() puts()

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