#include<stdio.h>
#include<conio.h>
struct
int roll;
char name[25];
float mark;
}std;
void main()
{
int n,i;
FILE *fp;
fp=fopen("d:\\cprg\student.txt","wb");
clrscr();
printf("\n Enter how many records: ");
scanf("%d",&n);
printf("enter student number name and marks for %d students",n);
for(i=0;i<n;i++)
{
scanf("%d%s%f",&std.roll,std.name,&std.mark);
fwrite(&std,sizeof(std),1,fp);
}
fclose(fp);
fp=fopen("d:\\cprg\student.txt","r");
printf("\nRoll\tName\tMarks Obtained\n");
while(fread(&std,sizeof(std),1,fp))
printf("%d\t%s\t%f\n",std.roll,std.name,std.mark);
fclose(fp);
getch();
}
No comments:
Post a Comment
Rahul-Notes