Hi, I have a text file that looks like this:
zoo.txt
The numbers are separated by spaces and newline characters, and I would like to read it into an array of identical structs: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
What file functions should I use?Code:struct _animal { int zoo, tag, pen, ability, diet, age; }; struct _animal zoo [numberOfAnimals];
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)



LinkBack URL
About LinkBacks



