home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 428_02 / libsrc / comgets.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-03-13  |  508 b   |  32 lines

  1. /*
  2. ** comgets.c
  3. **
  4. ** Pictor, Version 1.51, Copyright (c) 1992-94 SoftCircuits
  5. ** Redistributed by permission.
  6. */
  7.  
  8. #include "comlib.h"
  9.  
  10. /*
  11. ** Reads a '\r'-terminated string from the serial port.
  12. ** Returns 0 if successful, -1 if error.
  13. */
  14. int comgets(char *buffer,int max)
  15. {
  16.     int i;
  17.  
  18.     for(i = 0;i < max;i++) {
  19.         if(comgetc(&buffer[i])) {
  20.             buffer[i] = '\0';
  21.             return(-1);
  22.         }
  23.         if(buffer[i] == '\r') {
  24.             i++;
  25.             break;
  26.         }
  27.     }
  28.     buffer[i] = '\0';
  29.     return(0);
  30.  
  31. } /* comgets */
  32.