I have a text file contains the following:
apple meaning of apple
degree meaning of degree
How would I read each line and put them into array of char?
I have the folloing but need some advice on how to do it, please.
Code:#include<stdio.h> #include<stdlib.h> #define MAXLINE 10 void main(void) { char* readline[MAXLINE]; FILE *infile; char* line; int ch; if((infile = fopen("info.txt", "r"))==NULL ) { fprintf(stderr, "Error: Cannot open input file. "); exit(1); } line = (char *)malloc(sizeof(char)); while(fscanf(infile, "%s", line) != EOF) { printf("%s\n", line); while (ch = fgetc(infile) != '\n') { advice..... } } }



LinkBack URL
About LinkBacks



