initial import
[staff/goc4/2018bti7061.git] / c-5-structuresFiles / examples / c-files / writeFile2.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","w");
10
11
12 int i,n=0;
13 char *arrayOfStrings[10];
14
15 puts("Enter each string on a separate line");
16 puts("Type control D to finished");
17 int max=10;
18 int size;
19 do{
20
21 arrayOfStrings[n]=(char*) malloc(MAXSIZE * sizeof(char));
22 scanf("%s",arrayOfStrings[n]);
23 size = strlen(arrayOfStrings[n]);
24 n++;
25 }while(size > 0);
26 n--;
27 printf("List of strings (after sort)\n");
28 for(i=0;i<n;i++){
29 printf("%d) %s\n",(i+1),arrayOfStrings[i]);
30 fprintf(file_pointer,"%s\n",arrayOfStrings[i]);
31 }
32
33 fclose(file_pointer);
34
35
36
37
38
39 }