home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / progc / cfuncs.arj / FFILE.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-22  |  2.0 KB  |  64 lines

  1. #include <stdio.h>
  2. #include <fcntl.h>
  3. #include <io.h>
  4.  
  5. /*--------------------------------------------------------------*/
  6. /*----------------------------- fgetln -------------------------*/
  7. /*DESCRIPTION: Copies chars from the stream fp to dest until    */
  8. /*    a newline char is encountered.  Does not place the     */
  9. /*    newline ch in dest.  Dest is null terminated.        */
  10. /*                                */
  11. /*RETURNS: the address of dest or NULL on end of file or error    */
  12. /*USES: nothing                            */
  13. /*IN: ffile.c                             */
  14. /*--------------------------------------------------------------*/
  15.  
  16. char *fgetln(char *dest, FILE *fp)
  17. {
  18.    int i;
  19.  
  20.    i=0;
  21.    while((dest[i++]=fgetc(fp)) != '\n' && dest[i-1] != '\f')
  22.      if(dest[i-1] == EOF) return(NULL);
  23.  
  24.    dest[i-1] = '\0';
  25.  
  26.    return(dest);
  27. }
  28.  
  29. /*--------------------------------------------------------------*/
  30. /*------------------------ textprinter -------------------------*/
  31. /*DESCRIPTION: Due to a flaw in Turbo C that does not allow     */
  32. /*    you to change the stdprn stream to text mode, a new    */
  33. /*    stream directed to the printer opened for text must    */
  34. /*    be used.                                                  */
  35. /*                                */
  36. /*RETURNS: The address of a stream that will print to the     */
  37. /*       printer in text mode, or NULL on an error.        */
  38. /*                                */
  39. /*USES: nothing                            */
  40. /*IN: ffile.c                             */
  41. /*--------------------------------------------------------------*/
  42.  
  43. FILE *textprinter(void)
  44. /*--------RETURNS A STREAM TO THE PRINTER IN TEXT MODE,
  45.     a minor Turbo C miracle -------------------------*/
  46. {
  47.    FILE *textstream;
  48.    int texthandle;
  49.  
  50.    if((texthandle = dup(fileno(stdprn))) == -1 ||
  51.        setmode(texthandle, O_TEXT)==-1 ||
  52.        (textstream = fdopen(texthandle, "wt"))==NULL)
  53.         return(NULL);
  54.    else
  55.     return(textstream);
  56. }
  57.  
  58. int RecordsOnFile(FILE *file, int RecordSize)
  59. {
  60.    long filelen;
  61.  
  62.    filelen = filelength(fileno(file));
  63.    return((filelen==-1 || RecordSize<=0) ? 0: filelen/RecordSize);
  64. }