OK, I am creating a program that will load a text file of CDs into a prgram and add them to a structure. The text file will look like this:
(Each block of three is 1 CD)
Rating1
Title1
Artist1
Rating2
Title2
Artist2
...
Is there some way I can use fscanf to find the number of CDs, because right now it loads my CDs, and all the other garbage data around them. If I could find the number of Cds, I could put that in variable VAR in my program and all would be fine and dandy. Any ideas?
Code:
int loadFile (CD list[])
{
FILE *fp;
char name[50];
int i;
int n;
printf("Enter file name: ");
scanf("%s",name);
fp=fopen(name,"r");
for (i = 0; i < 100; i++) {
fscanf(fp,"%d\n",&list[i].rating);
getLine(list[i].title,50,fp);
getLine(list[i].artist,50,fp);
}
n=i;
fclose(fp);
return n;
}
Thanks in advance,
Evan