|
|
Study of file i/o - 5
|
|
#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; } |
|
|
|
|