home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / prof_c / util / getxline.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  768 b   |  39 lines

  1. /*
  2.  *    getxline -- get a line of text while expanding tabs,
  3.  *    put text into an array, and return a pointer to the
  4.  *    resulting null-terminated line
  5.  */
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10. #include <local\std.h>
  11.  
  12. char *
  13. getxline(buf, size, fin)
  14. char *buf;
  15. int size;
  16. FILE *fin;
  17. {
  18.     register int ch;    /* input character */
  19.     register char *cp;    /* character pointer */
  20.  
  21.     extern BOOLEAN tabstop(int);
  22.  
  23.     cp = buf;
  24.     while (--size > 0 && (ch = fgetc(fin)) != EOF) {
  25.         if (ch == '\n') {
  26.             *cp++ = ch;
  27.             break;
  28.         }
  29.         else if (ch == '\t')
  30.             do {
  31.                 *cp = ' ';
  32.             } while (--size > 0 && (tabstop(++cp - buf) == FALSE));
  33.         else
  34.             *cp++ = ch & ASCII;
  35.     }
  36.     *cp = '\0';
  37.     return ((ch == EOF && cp == buf) ? NULL : buf);
  38. }
  39.