Yurttas/PL/IL/C/F-mar11/04/02/00/03/double space.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   double_space.c
14*/
15
16
17#include <stdio.h>
18
19#include <string.h>
20
21#define MAX_SIZE_STRING 64
22
23int double_space(char *f_name,
24                 char *s[]) {
25  FILE *f_in;
26
27  int i = 0;
28
29  f_in = fopen(f_name, "r");
30
31  if(!f_in) {
32    printf("\ncannot open %s\n", f_name);
33    exit(1);
34  }
35
36  s[i] = (char*) malloc(MAX_SIZE_STRING*sizeof(char));
37
38  while(fgets(s[i], MAX_SIZE_STRING, f_in)) {
39    strcat(s[i], "\n");
40    ++i;
41    s[i] = (char*) malloc(MAX_SIZE_STRING*sizeof(char));
42  }
43
44  return i;
45}