Possible Duplicate:
reading a text file into an array in c
I'm struggling with reading a text file line by line into lines of an array. I am NOT allowed to use malloc or related commands. The latest code I found is this, which doesn't work:
void readfile(const char *filename) {
FILE *f;
f = fopen(filename, "r");
int linecount;
char inputError;
char a[500];
char array[50];
//struct cal_event one[200];
linecount = 0;
while(inputError != EOF) {
inputError = fscanf(f, "%s\n", array);
linecount++;
}
fclose(f);
char names[linecount][500];
f = fopen(filename, "r");
int i;
for(i = 1; i < linecount; i++)
fscanf(f, "%s", names[i]);
printf("%s ", names[i]);
fclose(f);
}
I need a code example please! Thanks so much!