#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fp,*fout;
int rollno,n,sub1,sub2,total,i;
char name[20];
float avg;
clrscr();
fp=fopen("student.dad","w");
if(fp==NULL)
{
puts("\n file cannot be opened");
getch();
exit(0);
}
printf("\n enter the number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("student %d",i+1);
printf("enter the rollno,name,marks in sub1,marks in sub2\n");
scanf("%d%s%d%d",&rollno,name,&sub1,&sub2);
fprintf(fp,"%d%s%d%d",rollno,name,sub1,sub2);
}
fclose(fp);
printf("\n student file created successfully ");
fp=fopen("student.dat","r");
if(fp==NULL)
{
puts("\n file cannot be opened");
getch();
exit(0);
}
fout=fopen("output.dat","w");
if(fout==NULL)
{
puts("\n file cannot be opened ");
getch();
exit(0);
}
fprintf(fout,"\n rollno name sub1 sub 2 total average \n\n");
while(fscanf(fp,"%d%s%d%d",&rollno,name,&sub1,&sub2)!=EOF)
{
total=sub1+sub2;
avg=total/2.0;
fprintf(fout,"%d\t%s\t%d\t%d\n",rollno,name,sub1,sub2,total,avg);
}
fclose(fout);
}
#include<conio.h>
#include<stdlib.h>
void main()
{
FILE *fp,*fout;
int rollno,n,sub1,sub2,total,i;
char name[20];
float avg;
clrscr();
fp=fopen("student.dad","w");
if(fp==NULL)
{
puts("\n file cannot be opened");
getch();
exit(0);
}
printf("\n enter the number of students:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("student %d",i+1);
printf("enter the rollno,name,marks in sub1,marks in sub2\n");
scanf("%d%s%d%d",&rollno,name,&sub1,&sub2);
fprintf(fp,"%d%s%d%d",rollno,name,sub1,sub2);
}
fclose(fp);
printf("\n student file created successfully ");
fp=fopen("student.dat","r");
if(fp==NULL)
{
puts("\n file cannot be opened");
getch();
exit(0);
}
fout=fopen("output.dat","w");
if(fout==NULL)
{
puts("\n file cannot be opened ");
getch();
exit(0);
}
fprintf(fout,"\n rollno name sub1 sub 2 total average \n\n");
while(fscanf(fp,"%d%s%d%d",&rollno,name,&sub1,&sub2)!=EOF)
{
total=sub1+sub2;
avg=total/2.0;
fprintf(fout,"%d\t%s\t%d\t%d\n",rollno,name,sub1,sub2,total,avg);
}
fclose(fout);
}
thnx i was searching for this
ReplyDeletethnx i was searching for this
ReplyDeleteThis comment has been removed by the author.
ReplyDelete