hello,
i have a problem with printing records.M_F on the screen while reading from a binary file.
i'll appreciate any help !
THank U
#include "stdafx.h"
#include <stdio.h>
#include <stdlib.h>
enum sex {m, f};
struct student {
char fname[40];
sex M_F;
int S_AGE;
double W;
}; student records[10];
int _tmain(int argc, _TCHAR* argv[])
{
FILE *fp;
if (( fp = fopen ( "data.data", "rb" ) ) == NULL )
{
printf ( "Cannot open file\n" );
exit ( 1 );
}
fread(records,200,3,fp);
for(int i=0; i<10; i++)
{
printf("%s %i %2.2f\n", records[i].fname,records[i].age,records[i].weight);
// i tried printf("%s",records[i].M_F) but i got 0 for (m) and 1 for (f)
// do i have to write a if statement ?
}
fclose ( fp );
return 0;
}