home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Trees / V7 / usr / src / cmd / rev.c < prev    next >
Encoding:
C/C++ Source or Header  |  1979-01-10  |  616 b   |  45 lines

  1. #include <stdio.h>
  2.  
  3. /* reverse lines of a file */
  4.  
  5. #define N 256
  6. char line[N];
  7. FILE *input;
  8.  
  9. main(argc,argv)
  10. char **argv;
  11. {
  12.     register i,c;
  13.     input = stdin;
  14.     do {
  15.         if(argc>1) {
  16.             if((input=fopen(argv[1],"r"))==NULL) {
  17.                 fprintf(stderr,"rev: cannot open %s\n",
  18.                     argv[1]);
  19.                 exit(1);
  20.             }
  21.         }
  22.         for(;;){
  23.             for(i=0;i<N;i++) {
  24.                 line[i] = c = getc(input);
  25.                 switch(c) {
  26.                 case EOF:
  27.                     goto eof;
  28.                 default:
  29.                     continue;
  30.                 case '\n':
  31.                     break;
  32.                 }
  33.                 break;
  34.             }
  35.             while(--i>=0)
  36.                 putc(line[i],stdout);
  37.             putc('\n',stdout);
  38.         }
  39. eof:
  40.         fclose(input);
  41.         argc--;
  42.         argv++;
  43.     } while(argc>1);
  44. }
  45.