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

 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_11.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
28  int i = 0, j;
29
30  s[i] = (char*) malloc(MAX_SIZE_STRING*sizeof(char));
31
32  while(fgets(s[i], MAX_SIZE_STRING, i_f)) {
33    strcat(s[i], "\n");
34    ++i;
35    s[i] = (char*) malloc(MAX_SIZE_STRING*sizeof(char));
36  }
37
38  for(j=0; j<i; ++j)
39    fprintf(o_f, "%s", s[j]);
40}
41
42
43int main(int argc, char *argv[]) {
44
45  FILE *f_in,
46       *f_out;
47
48  if(argc!=3) {
49    printf("\nUsage: %s infile outfile\n", argv[0]);
50    exit(1);
51  }
52
53  f_in = fopen(argv[1], "r");
54
55  if(!f_in) {
56    printf("\ncannot open %s", argv[1]);
57    exit(1);
58  }
59
60  f_out = fopen(argv[2], "w");
61
62  double_space(f_in,
63               f_out);
64
65}