Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Turbo C - <b>gets() read a line from 'stdin'</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
gets()                   Read a Line from 'Stdin'

 #include   <stdio.h>

 char       *gets(buffer);
 char       *buffer;                     Storage location for input string

    gets() reads a string from the standard input 'stdin' and stores it
    in 'buffer'.  The string consists of all characters up to and
    including the first new-line character ('\n').  The new-line
    character is replaced with a null character ('\0').

    Returns:    The string argument 'string'.  A NULL pointer indicates
                an error or end-of-file condition.  Use ferror() or
                feof() to determine whether an error or eof occurred.

      Notes:    fgets() is like gets(), but fgets() retains the new-line
                character.

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

    The following statements get a string from 'stdin' and print it to
    the screen.

          #include <stdio.h>

          char buffr[80];
          char *rslt;

          main()
          {
              if (!feof(rslt = gets(buffr)))
                    printf("\n%s",rslt);
           }

See Also: fgets() fputs() puts() feof() ferror()

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