home *** CD-ROM | disk | FTP | other *** search
/ Mega CD-ROM 1 / megacd_rom_1.zip / megacd_rom_1 / MAGAZINE / PROGJOUR / PJ_9_4.ZIP / V_GETS.C < prev    next >
C/C++ Source or Header  |  1991-05-03  |  718b  |  31 lines

  1. /*     v_gets.c- Get String from Viewport */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <conio.h>
  6. #include <tools/viewport.h>
  7.  
  8. int v_gets( viewport *v, int n, char *s )
  9. {
  10.     /* Copy at most n-1 characters into s, starting at current cursor
  11.      * position into s. Return number of characters read.
  12.      */
  13.  
  14.     char *start = s;
  15.  
  16.     if( v->magic != VMAGIC )
  17.         return 0;
  18.  
  19.     while( --n > 0 )
  20.     {
  21.         *s++ = v_getc( v );
  22.         if( !v_advance(v) )     /* then we just read the last character */
  23.         {                       /* on the line                          */
  24.             *s = '\0';
  25.             return 0;
  26.         }
  27.     }
  28.     *s = '\0';
  29.     return (s - start);
  30. }
  31.