Yurttas/PL/IL/C/F-mar11/04/02/00/01/io gs 01.c

From ZCubes Wiki
Jump to navigation Jump to search
 1/*
 2   Copyright(C) 1998
 3   All Rights Reserved. Salih Yurttas, ZCubes, BitsOfCode Software Systems, Inc..
 4
 5   Permission to use, copy, modify, and distribute this
 6   software and its documentation for EDUCATIONAL purposes
 7   and without fee is hereby granted provided that this
 8   copyright notice appears in all copies.
 9
10   date   : January 1, 1998.
11   author : Salih Yurttas.
12
13   io_gs_01.c
14*/
15
16
17#include <stdio.h>
18
19#include <string.h>
20
21#define MAX_NO_STRING 256
22#define MAX_SIZE_STRING 64
23
24void double_space(FILE *i_f,
25                  FILE *o_f) {
26  char *s[MAX_NO_STRING];
27  char t[MAX_SIZE_STRING];
28
29  int i = 0, j;
30
31  while(fgets(t, MAX_SIZE_STRING, i_f)) {
32    s[i] = (char*) malloc(MAX_SIZE_STRING*sizeof(char));
33    strcpy(s[i], t);
34    strcat(s[i], "\n");
35    ++i;
36    fprintf(o_f, "%s", t);
37  }
38  fprintf(o_f, "\n");
39
40  for(j=0; j<i; ++j)
41    fprintf(o_f, "%s", s[j]);
42}
43
44
45int main(int argc, char *argv[]) {
46
47  FILE *f_in,
48       *f_out;
49
50  if(argc!=3) {
51    printf("\nUsage: %s infile outfile\n", argv[0]);
52    exit(1);
53  }
54
55  f_in = fopen(argv[1], "r");
56
57  if(!f_in) {
58    printf("\ncannot open %s", argv[1]);
59    exit(1);
60  }
61
62  f_out = fopen(argv[2], "w");
63
64  double_space(f_in,
65               f_out);
66
67}