home *** CD-ROM | disk | FTP | other *** search
/ Shareware Overload / ShartewareOverload.cdr / progm / elem-c.zip / PRINTAB.C < prev    next >
C/C++ Source or Header  |  1985-05-18  |  2KB  |  86 lines

  1. /*      Print an ASCII file and change tab characters to
  2.         spaces.
  3.                 By Paul Sumberg  1985
  4. */
  5. #include "stdio.h"
  6.  
  7. main(argc,argv)
  8. /*     *    *    arguments are passed to main when program is invoked.
  9.             The proper format is "PROGRAM filename.ext"            *    *    */
  10. int argc;
  11. char **argv;
  12.     {
  13.         /*    *    *    initialize variables    *    *    */
  14.         FILE *read_file, *out_file, *fopen ();
  15.         char in_name[15];
  16.         int c;
  17.         char next_char;
  18.         int counter = 0;
  19.         int lines = 0;
  20.         /*    *    *    test for proper number of arguments    *    *    */
  21.         if(argc != 2)
  22.             {
  23.             printf("\nUsage: Print filename.ext\n");
  24.             exit(1);
  25.             }
  26.  
  27. /*    *    *    open input file that was given to main as argument    *    *    */
  28.  
  29.         read_file = fopen (argv[1], "r");
  30.  
  31.             /*         RATS! cant open it.     */
  32.             if ( read_file == NULL )
  33.             printf("couldn't open %s for reading.\n",argv[1]);
  34.             else
  35.             {
  36.  
  37.             /*    *    open "printer" file   for output..    *    */
  38.  
  39.             out_file = fopen ("prn:" , "w");
  40.                 if (out_file == NULL )
  41.                     Printf("check printer.\n");
  42.  
  43.                 else
  44.  
  45.                    {
  46.                     /*    *    give printer some linefeeds.    *    */
  47.                     fprintf(out_file,"\n\n\n");
  48.  
  49. /*    read each character and send to printer,replacing TABs with SPACES.    */
  50.                     while ( (c = getc(read_file)) != EOF )
  51.                         {
  52.                         next_char = c;    
  53.  
  54.                 /*    * check page length and if near end, give FF    *    */
  55.                         if (next_char == '\r')
  56.                             {
  57.                             ++lines;
  58.                             next_char - '\0';
  59.                             }
  60.                                 if(lines >= 60)
  61.                                 {    putc('\f',out_file);
  62.                                     lines = 0;
  63.  
  64.                                 /*    give new page some linefeeds    */
  65.                                     fprintf("\n\n\n");
  66.                                 }    
  67.  
  68.  
  69.                     /*    *    Is this sucker the tab character??    *    */
  70.                         if (next_char == '\t')
  71.                             {
  72.                             for(counter = 0; counter != 3; ++counter)
  73.                                 putc(' ', out_file);
  74.                             continue;
  75.                             }
  76.  
  77.                 /*    *    *    Stuff that thing out the printer port.    *    *    */
  78.                         putc (c, out_file);        
  79.                         }
  80.                         printf("file has been PRINTED!\n");
  81.                     }
  82.         }
  83.                 fclose(out_file);    /*    *    *    Put files to bed
  84.                 fclose(read_file);    *    *    *    Night Night.    *    *    */
  85.     }