home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / BBS / MISC / HSRC_117.ZIP / FGETSX.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-21  |  897 b   |  58 lines

  1. #include "io.h"
  2. #include "stddef.h"
  3. #include "stdarg.h"
  4.  
  5.  
  6. /* An fgets() for shared i/o */
  7.  
  8. char * pascal fgetsx (char *str,int num,int handle) {
  9.  
  10.     char *p;
  11.     long pos;
  12.     int x;
  13.  
  14.     if (eof(handle)) {
  15.         *str=0;
  16.         return NULL;
  17.     }
  18.     pos=tell(handle);
  19.     x=_read(handle,str,num-1);
  20.     if (x<1) {
  21.         *str=0;
  22.         return NULL;
  23.     }
  24.     str[x]=0;
  25.     p=str;
  26.     while(*p && *p!='\r' && *p!='\n') p++;
  27.     if(!*p) return str;
  28.     if(*p=='\r') {
  29.         *p='\n';
  30.         if (p[1]=='\n') {
  31.             p++;
  32.             *p=0;
  33.         }
  34.     }
  35.     p++;
  36.     *p=0;
  37.     lseek(handle,pos+((long)((unsigned int)p-(unsigned int)str)),SEEK_SET);
  38.     return str;
  39. }
  40.  
  41.  
  42. /* An fprintf() for shared i/o */
  43.  
  44. int cdecl ffprintf (int handle,char *string,...) {
  45.  
  46.  unsigned int x;
  47.  char buffer[512];
  48.  
  49.    va_list ap;
  50.    va_start(ap,string);
  51.    vsprintf(buffer,string,ap);
  52.    va_end(ap);
  53.    x=strlen(buffer);
  54.    _write(handle,buffer,x);
  55.    return x;
  56. }
  57.  
  58.