Hi, I have a text file that looks like this:
zoo.txt
Code:
1 0 0 90 3 1
1 1 0 62 1 2
1 2 0 64 1 2
1 3 0 65 1 2
1 4 0 61 1 2
1 5 0 62 1 2
1 6 0 58 1 2
1 7 1 57 1 1
The numbers are separated by spaces and newline characters, and I would like to read it into an array of identical structs:
Code:
struct _animal {
int zoo, tag, pen, ability, diet, age;
};
struct _animal zoo [numberOfAnimals];
What file functions should I use?
I tried fscanf but I have to use a lot of repetition, and I cant use fread because it's a text file not a binary file
Also, how do I find out the value of numberOfAnimals, besides the method below
Code:
FILE *inputfile;
inputFile = fopen ("zoo.txt", "r");
while ( (c = getc (inputFile) ) != EOF) {
numberOfAnimals+= (c == '\n');
}
fclose (inputFile)
printf ("%d", numberOfAnimals)