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;
}
printf("%s",records[i].M_F == 0 ? "Male" : "Female")
printf("%s",records[i].M_F == 0 ? "Male" : "Female")

is that same as condition ?! like if records.m_f == 0 print male else print female ?!

is that same as condition ?! like if records.m_f == 0 print male else print female ?!

yes.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.