i'm doing an assignment with binary files and link lists.
the following bit of code kinda works but it repeats the last entry from the file. I can't understand why. Any suggestions wud be greatly appreciated
Code:
void readfromfile()
{
struct Copy{
int ccode;
char cdescription[50];
char clicense;
char cspec[50];
int cunits;
int creorder;
float ccost;
};
struct Copy copy;
FILE *frPtr;
if ((frPtr = fopen("software", "rb"))==NULL){
printf("Cannot open file \n");
}
else
{
fseek (frPtr,0,SEEK_SET);
while (!feof(frPtr))
{
fread (©,sizeof(struct Copy),1,frPtr);
printf("%d\n\n", copy.ccode);
printf("%s\n", copy.cdescription);
printf("%c\n\n", copy.clicense);
printf("%s\n", copy.cspec);
printf("%d\n\n", copy.cunits);
printf("%d\n\n", copy.creorder);
printf("%f\n\n", copy.ccost);
system("pause");
}
}
fclose(frPtr);
printf("To read data from a file if the file exists and load it into the Linked List.\n");
system("pause");
}