Study of file i/o - 5 Writing block of data to a file with fwrite( ).

#include <stdio.h>

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

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

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

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

printf("\nRoll number :");
scanf("%d", &s.rollno);
printf("Name :");
fflush(stdin);
gets(s.name);
printf("Percentage :");
scanf("%f", &s.percent);

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

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