File: reverse.c

package info (click to toggle)
thrust 0.89c-3.5
  • links: PTS
  • area: main
  • in suites: squeeze, wheezy
  • size: 2,080 kB
  • ctags: 996
  • sloc: ansic: 20,409; sh: 2,483; makefile: 332
file content (44 lines) | stat: -rw-r--r-- 716 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

/* Written by Peter Ekberg, peda@lysator.liu.se */

#ifdef HAVE_CONFIG_H
#include "../src/config.h"
#endif

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#include <stdio.h>
#include <stdlib.h>

int main(int argc,char *argv[])
{
  long j;
  int i,r;
  int ch;
  FILE *si, *so;
  
  if(argc != 2) {
    fprintf(stderr, "%s: Usage %s [number]\n", argv[0], argv[0]);
    exit(1);
  }

  r=atoi(argv[1]);

  si = fdopen(fileno(stdin), "rb");
  so = fdopen(fileno(stdout), "wb");

  if(fseek(si, 0L, SEEK_END))
    perror(argv[0]);
  for(j=ftell(si)/r-1; j>=0; j--) {
    if(fseek(si, j*r, SEEK_SET))
      perror(argv[0]);
    for(i=0; i<r; i++) {
      ch=fgetc(si);
      fputc(ch, so);
    }
  }
  
  return(0);
}