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