initial import
[staff/goc4/2018bti7061.git] / c-5-structuresFiles / examples / c-files / readFile.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #define MAXSIZE 16
6
7 int main(){
8 FILE *file_pointer;
9 file_pointer = fopen("output2.txt","r");
10
11
12 int i,n=0;
13 char *arrayOfStrings[10];
14
15 puts("Reading strings from the file: output2.txt");
16 int max=10;
17 int size;
18 do{
19
20 arrayOfStrings[n]=(char*) malloc(MAXSIZE * sizeof(char));
21 fscanf(file_pointer,"%s",arrayOfStrings[n]);
22 size = strlen(arrayOfStrings[n]);
23 n++;
24 }while(size > 0);
25 n--;
26 printf("List of strings\n");
27 for(i=0;i<n;i++){
28 printf("%d) %s\n",(i+1),arrayOfStrings[i]);
29 }
30
31 fclose(file_pointer);
32
33
34
35
36
37 }