home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c082_122 / 1.ddi / CLIBSRC1.ZIP / GETS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  1.4 KB  |  51 lines

  1. /*------------------------------------------------------------------------
  2.  * filename - gets.c
  3.  *
  4.  * function(s)
  5.  *        gets - gets a string from a stream
  6.  *-----------------------------------------------------------------------*/
  7.  
  8. /*
  9.  *      C/C++ Run Time Library - Version 5.0
  10.  *
  11.  *      Copyright (c) 1987, 1992 by Borland International
  12.  *      All Rights Reserved.
  13.  *
  14.  */
  15.  
  16.  
  17. #include <stdio.h>
  18.  
  19. /*---------------------------------------------------------------------*
  20.  
  21. Name            gets - gets a string from a stream
  22.  
  23. Usage           char *gets(char *string);
  24.  
  25. Prototype in    stdio.h
  26.  
  27. Description     gets reads a string into string from the
  28.                 standard input stream stdin. The string is terminated by a
  29.                 newline character, which is replaced in @i{string} by a null
  30.                 character (\0).
  31.  
  32. Return value    on success, returns the string argument string;
  33.                 else returns NULL on end-of-file or error.
  34.  
  35. *---------------------------------------------------------------------*/
  36. char *gets(char *s)
  37. {
  38.         register int     c;
  39.         register char   *P;
  40.  
  41.         P = s;
  42.  
  43.         while ((c = getc (stdin)) != EOF && c != '\n')
  44.                 *P++ = c;
  45.  
  46.         if (EOF == c && P == s)
  47.                 return( NULL );
  48.         *P = 0;
  49.         return(((ferror (stdin)) ? NULL : s));
  50. }
  51.