home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_100 / 161_01 / fmttbl.c < prev    next >
C/C++ Source or Header  |  1985-08-29  |  2KB  |  85 lines

  1. /* fmttbl -  Sam Yanuck
  2.  * Accumulate space and time data for sample codes, each run
  3.  * recorded in a file.
  4.  */
  5. #include <stdio.h>
  6. #define TIMEF "time.tbl"
  7. #define SPACEF "space.tbl"
  8. char fprefix[20] = "";
  9. char foutname[64] = "";
  10.  
  11. main(ac, av)
  12.     int ac;
  13.     char *av[];
  14.     {
  15.     short i, nskip, j;
  16.     short lastrow;
  17.     static char space[5][100][7] = {0};
  18.     static char time[5][100][13] = {0};
  19.     static char sample[100][21] = {0};
  20.     FILE *fpin, *fpout;
  21.  
  22.     if (strcmp(av[1], "-p") == 0)
  23.         {
  24.         strcpy(fprefix, av[2]);
  25.         nskip = 2;
  26.         }
  27.     else
  28.         nskip = 0;
  29.     for (i = 1; i + nskip < ac; ++i)
  30.         {
  31.         fpin = fopen(av[i+nskip], "r");        /* open input files sequentially */
  32. #if 0
  33. printf("fname=<%s>\n", av[i+nskip]);
  34. #endif
  35.         if (fpin == NULL)                  
  36.             error("can't open", av[i+nskip]);
  37.  
  38.         while (getc(fpin) != '\n')       /* bypass input of col. headings */
  39.             ;                            
  40.         for (j = 0;
  41.             0 < fscanf(fpin,
  42.             "%20c%*2c%6c%*2c%12c", sample[j], space[i-1][j], time[i-1][j]);
  43.             ++j)
  44.             {
  45. #if 0
  46. printf("sample=<%20s> space=<%6s> time=<%12s>\n",
  47.     sample[j], space[i-1][j], time[i-1][j]);
  48. #endif
  49.             while (getc(fpin) != '\n')     /* bypass remaining whitespace */
  50.                 ;                            
  51.             }
  52.         lastrow = j-1;                        /* set array boundary */
  53.         fclose(fpin);                        
  54.         }
  55.  
  56.     strcpy(foutname, fprefix);
  57.     strcat(foutname, TIMEF);
  58.     fpout = fopen(foutname, "w");        /* print sample code, then */
  59.     if (fpout == NULL)                 /* time from each input file */
  60.         error("can't open (write)", foutname);  
  61.     for (j = 0; j <= lastrow; ++j)
  62.         {
  63.         fprintf(fpout, "%20s  ", sample[j]);
  64.         for (i = 1; i < ac-nskip; ++i)
  65.             fprintf(fpout, "%10.10s ", time[i-1][j] + 2);
  66.         fprintf(fpout, "\n");
  67.         }
  68.     fclose(fpout);
  69.  
  70.     strcpy(foutname, fprefix);
  71.     strcat(foutname, SPACEF);
  72.     fpout = fopen(foutname, "w");        /* same structure as above */
  73.     if (fpout == NULL)               
  74.         error("can't open", foutname);
  75.     for (j = 0; j <= lastrow; ++j)
  76.         {
  77.         fprintf(fpout, "%20s  ", sample[j]);
  78.         for (i = 1; i < ac-nskip; ++i)
  79.             fprintf(fpout, "%10.10s ", space[i-1][j]);
  80.         fprintf(fpout, "\n");
  81.         }
  82.     fclose(fpout);
  83.     
  84.     }
  85.