If the following doesn't fix the problem then the problem is in the way the data is being input as posted in your first code snippet.
int i,n1;
FILE *file = fopen("db.dat", "wb");
cout<<"Writing into file\n";
if ( file != NULL )
{
fwrite(r, sizeof(r[0]), n,file);
fclose(file);
}
cout<<"Writing completed\n";
and
struct rec re;
FILE *file = fopen("db.dat", "rb");
while( fread(&re,sizeof re,1, file) > 0)
{
cout<<re.id<<re.name<<re.mark<<'\n';
}
Since this is a c++ program you really should use ofstream and ifstream classes instead of FILE*.
Ancient Dragon
Retired & Loving It
30,049 posts since Aug 2005
Reputation Points: 5,662
Solved Threads: 2,343