hello coders,

I am facing problem to filing my programm. it opens the intended file but problem is it is not saving any datas. I want to see the results in notepad or word. I am using windows vista and my soft is dev C++. I dont want to use <iostream> at this moment, I want to use FILE option instead. Here is my log given below, if anyone has got any idea and can test it in there own computer and can post the result will be highly appreciated.

#include <stdio.h>
main()
{
FILE *f1;
printf("Data Input\n\n");
f1=fopen("Student marksheet","w");

struct personal
{
char name[20];
char birthday[12];
int id;
char course [10];
};
{
struct personal person;
printf("input values\n");

scanf("%s %s %d %s",&person.name,&person.birthday,&person.id,&person.course);
printf("%s %s %d %s\n",person.name,person.birthday,person.id,person.course);
}
int n, m, i, j,t,roll_number, marks, total;
float average;
printf("enter number of students and subjects\n");
scanf("%d %d",&n,&m);
for(i=1;i<=10;i++);
{
printf("Enter roll_number");
scanf("%d",&roll_number);
total=0;
printf("\n Enter marks of %d subjects for roll No.%d \n",m,roll_number);
for(j=1;j<=4;j++)

{
scanf ("%d",&marks);
total=total+marks;
}
average=total/m;
printf("Total marks=%d",total);
printf("average=%f\n", average);

if (average>=70)
printf("Grade A\n\n");
else if (average>=60)
printf("Grade B \n\n");
else if (average>=50)
printf ("Grade C \n\n");
else if (average>=45)
printf("Grade D\n\n");
else if (average>=40)
printf("Grade E\n\n"); 
else 
printf("(***Fail***)");


printf("\nData Output\n\n");
f1=fopen("Student Marksheet","r");
fclose(f1);
}
getch();
}

Regards

You are not trying to save anything to the file, i.e. there are no calls to any function that would write to the file. If you are familiar with printf(), try looking up fprintf() and using it to write to the file.

Last but not least, learn to use the code tags when you post code.

This article has been dead for over six months. Start a new discussion instead.