home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / alde_c / misc / lib / dlibssrc / gets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-10-06  |  584 b   |  26 lines

  1. #include <stdio.h>
  2.  
  3. char *gets(data)
  4. register char *data;
  5. /*
  6.  *    Get data from stdin and puts it in the <data> buffer.  Input is
  7.  *    terminated when a newline is read.  The    newline will be replaced
  8.  *    by a '\0' to terminate the string.  A pointer to the start of
  9.  *    <data> is returned, or NULL for EOF.
  10.  */
  11. {
  12.     register char *p = data;
  13.     register int c;
  14.  
  15.     while(((c = fgetc(stdin)) != EOF) && (c != '\n')) {
  16.         if(c == '\b') {
  17.             if(p > data)
  18.                 --p;
  19.         }
  20.         else
  21.             *p++ = c;
  22.     }
  23.     *p = '\0';
  24.     return(((c == EOF) && (p == data)) ? NULL : data);  /* NULL == EOF */
  25. }
  26.