home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c065 / 1.ddi / CLIB1.ZIP / GETS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  1.7 KB  |  52 lines

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