...

View Full Version : file handling in c



tanv@vice
11-16-2008, 06:48 PM
hi...i tried a simple code in file handling that inputs name roll no. and cgpa of a student in a structure and saves it in a file and then displays it
but the progarm is not giving the desired output.pls help..i m new in the programing scene.:confused:
here is the code:

#include<stdio.h>
#include<conio.h>
struct student
{
int rolno;
char name[20];
float cgpa;
}s[10];
void main()
{
struct student s[10];
FILE *fp;
int i;
clrscr();
for(i=0;i<10;i++)
{
printf("enter rolno");
scanf("%d",&s[i].rolno);
printf("name");
gets(s[i].name);
printf("cgpa");
scanf("%f",&s[i].cgpa);
}
fopen("c:\\S.DAT","w+");
fwrite(s,sizeof(struct student),10,fp);
rewind(fp);
for(i=0;i<10;i++)
{
fprintf(fp,"%d %s %f \n" , s[i].rolno,s[i].name,s[i].cgpa);
}
fclose(fp);
}

Millenia
11-16-2008, 06:56 PM
Can you be more specific about you're problem? In more detail
Also can you wrap you're code in [code] tags please
Thanks :)

tanv@vice
11-16-2008, 07:32 PM
the problem is tht i m trying to print wotevr is stored in the file but actually it is nt diaplayed on the screen



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum