home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0020 - 0029 / ibm0020-0029 / ibm0028.tar / ibm0028 / GRLF-C-2.ZIP / GFUNC / SGETS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-30  |  1018 b   |  45 lines

  1. /*
  2.  * sgets.c
  3.  * contains: sgets()
  4.  *
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include "gfuncts.h"
  9.  
  10. /*
  11.  *  char *
  12.  * sgets(dest,source,maxc)
  13.  *
  14.  * ARGUMENT
  15.  *  (char *)    dest    -    Destination string
  16.  *  (char *)    source    -    Source string
  17.  *  (int)    maxc    -    Maximum number of characters to transfer
  18.  *
  19.  * DESCRIPTION
  20.  *  Used for extracting lines from multi-line buffers.  Reads characters from
  21.  *  the source string into the destination string until a new line is read
  22.  *  from the source string or maxc characters have been read or a NULL
  23.  *  character has been read.
  24.  *
  25.  * RETURNS
  26.  *  pointer to next line in string or NULL if at end of string
  27.  *
  28.  * AUTHOR
  29.  *   Copyright (C)1987-1990 Greenleaf Software Inc. All Rights Reserved.
  30.  */
  31. char* GF_CONV sgets(dest,source,imax)
  32. char *dest,*source;
  33. int imax;
  34. {
  35.     if(!*source) {
  36.         *dest='\0';
  37.         return(NULL);
  38.     }
  39.     for(;*source&&*source!='\n'&&imax;--imax,++source,++dest)
  40.         *dest=*source;
  41.     *dest='\n';
  42.     *(dest+1)='\0';
  43.     return((*source)?source+1:source);
  44. }
  45.