|
|
1.1 ! root 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: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.