Hello guys! i really need your help.
In my program, I am reading the contents of the file.
File looks like this:
1 ART ACE APE
2 BAT BOY
3 CAT COP CUP CAP CUT
I want to store the words in an array. one array per line.
I just would like to ask how do you separate the number from the words when reading from the file? And how will the computer know that it is already going to a new line, thus must fill the next array. Knowing when the next line starts troubles me because each line could have any number of words, max of 8 words per line.
I have been thinking of these for the past three days,
and so far this is what I got,
i know this is short but with this code, I already get a segmentation fault. i don't know why.
Please, help me.
int main() {
FILE *ifp, *ofp;
ofp = fopen("input.txt", "a");
ifp = fopen("output.txt", "r");
char data[8][8][3];
int a,b,z;
for (a=0; a<20; a++)
for (b=0;b<20; b++)
for (z=0; z<3; z++)
data[a][b][z] = ' ';
char number[20];
char c;
while ((c = getc(ifp)) != EOF) {
printf(c); // i did this to check if it is successful reading
}
}
please shed some light. thank you very much.