Following is my code for inserting data into file
Note: I have one structure named record for that
fwrite(&record, sizeof(record),1,fptr);
I use the above code in a loop, to enter multiple records.
Now, I have my data reading program as this:
do {
fread(&record, sizeof(record), 1, fptr);
printf("\nName: %s \nAddress: %s \nClass Level: %d \nTelepone: %ld",record.name, record.address, record.classlevel, record.telephone);
}while (feof(fptr));
But it only displays only first record.
I also tried using fseek() for that as follows:
do {
fread(&record, sizeof(record), 1, fptr);
printf("\nName: %s \nAddress: %s \nClass Level: %d \nTelepone: %ld",record.name, record.address, record.classlevel, record.telephone);
fseek(fptr,sizeof(record)+1, SEEK_SET);
}while (feof(fptr));
And Still It didn’t work!! I am trying to do an small project on C and This File Handling is just getting on my nerves.
change this:
to this: