Study of file i/o - 6 Reading block of data from a file with fread( ).

#include <stdio.h>

typedef struct student
{
int rollno;
char name[40];
float percent;
}student;

int main(void)
{
FILE *fp;
student s;

fp = fopen("stu", "rb");

if(fp == NULL)
{
printf("\nUnable to open file for reading");
return 1;
}

fread((student *) &s, sizeof(student), 1, fp);

printf("\nRoll number : %d", s.rollno);
printf("\nName : %s", s.name);
printf("\nPercentage : %f", s.percent);

fclose(fp);

return 0;
}

No comments:

Post a Comment

kiss on google ads if you are anonymous because your ip is trackable.thank you.

......from.admin