home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 183_01 / address.c < prev    next >
C/C++ Source or Header  |  1986-02-04  |  1KB  |  66 lines

  1. /*
  2.  *  address     Address a standard letter using the file 'address' (created
  3.  *              by the letter program.
  4.  */
  5. #include <stdio.h>
  6.  
  7. #define HEAD 4
  8. #define LENGTH 24
  9. #define PO 5;
  10.  
  11. #define WIDTH 95
  12.  
  13. #define ERROR -1
  14. /*
  15.  *  read address into this array
  16.  */
  17. #define MAXLINES 10
  18. char *lines[MAXLINES];
  19.  
  20. FILE *fd, *printer;
  21.  
  22. main()
  23. {
  24.     char buff[80];
  25.     int max, j, offset, len, count;
  26.     char *malloc();
  27.  
  28.     /*
  29.      *  open the address file
  30.      */
  31.     if ( (fd = fopen("address", "r")) == 0) {
  32.         printf("address file does not exist.\n");
  33.         exit(ERROR);
  34.     }
  35.     printer = fopen("LPT1", "w");
  36.  
  37.     for(count=0, max=0; count<MAXLINES; count++) {
  38.         if ( fgets(buff, 80, fd) == 0)
  39.             break;
  40.         else {
  41.             len = strlen(buff);
  42.             lines[count] = malloc(80);
  43.             if (len > max)
  44.                 max = len;
  45.             strcpy(lines[count], buff);
  46.         }
  47.     }           
  48.     offset = ( (WIDTH - max) / 2) + PO
  49.     for(j=0; j<offset; j++)
  50.         buff[j]=' ';
  51.     buff[j] = '\0';
  52.  
  53.     offset = ( LENGTH - count ) / 2 - HEAD;
  54.  
  55.     for(j=0; j<offset; j++)
  56.         fputs("\n", printer);
  57.  
  58.     for(j=0; j<count; j++) {
  59.         fprintf(printer, "%s%s", buff, lines[j]);
  60.     }
  61.     
  62.     fputs("\014", printer);
  63.     fclose(fd);
  64.     fclose(printer);
  65. }
  66.