I am new to C and I am confused how I can read through a file and store each line to an index of an array.
Example file:
What color is the sky?
Red
Orange
Yellow
Blue
Desired result of code:
input[0] = What color is the sky?
input[1] = Red
input[2] = Orange
input[3] = Yellow
input[4] = Blue
Hhere is what I have so far:
char input[60];
//declare string array of size 80, for 80 lines
for(int i = 0; fgets(input, sizeof(input), inFile)!=NULL; i++){
//string[i] = input; storing this line to the string index
}
//later on use the string[80] that now has all lines
I understand that declaring input[60]
is only determining the length of each line, not the number of lines. I am so used to thinking about strings in other coding languages, that the use of char is throwing me off. I have tried video tutorials but they didn't help me.