#include<stdio.h> #include<conio.h> #include<stdlib.h> #define no 2 struct { int r_no; char name[30]; int m1; }s[no]; void main() { int i; FILE *fp; clrscr(); fp=fopen("C:\Student.dat","w"); if(fp==NULL) { printf("File cannot be created!"); exit(0); } for(i=0;i<no;i++) { printf("\nData collection for student%d:",i+1); printf("\nRoll no: "); scanf("%d",&s[i].r_no); flushall(); printf("Name: "); gets(s[i].name); printf("Mark: "); scanf("%d",&s[i].m1); } fwrite(s,sizeof(s),no,fp); rewind(fp); printf("\nFailed students' info:\n"); printf("\nRollno Name\t\t\tMarks"); printf("\n------ ----\t\t\t-----"); fread(s,sizeof(s),no,fp); for(i=0;i<no;i++) if(s[i].m1<40) printf("\n%-5d %-25s%-7d",s[i].r_no,s[i].name,s[i].m1); fclose(fp); getch(); }
WHAT'S NEW?
Loading...
0 comments:
Post a Comment