Please help me find error in the program
#include<stdio.h>
#include<conio.h>
struct student
{
int roll;char name;
}s1;
FILE *fp;
void main()
{
create_file();
read_file();
getch();
}
void create_file()
{
char reply;
fp=fopen("student.txt","w");
if(fp==NULL)
{
printf("\n the file cannot be opened");
exit(1);
}
do
{
printf("\n enter the student's roll no and name: ");
scanf("%d%s",&s1.roll,s1.name);
fprintf(fp,"\n the roll no is:%d \t the name is %s",s1.roll,s1.name);
printf("\n do u wish to add new records(Y\N): ");
reply=getch();
}while(reply=='Y');
fclose(fp);
}
void read_file()
{
fp=fopen("student.txt","w");
if(fp==NULL)
{
printf("\n the file cannot be opened");
exit(1);
}
while(!feof(fp))
{
fscanf(fp,"%d%s",&s1.roll,s1.name);
printf("\n roll no=%d\tname=%s",s1.roll,s1.name);
}
fclose(fp);
}
#include<conio.h>
struct student
{
int roll;char name;
}s1;
FILE *fp;
void main()
{
create_file();
read_file();
getch();
}
void create_file()
{
char reply;
fp=fopen("student.txt","w");
if(fp==NULL)
{
printf("\n the file cannot be opened");
exit(1);
}
do
{
printf("\n enter the student's roll no and name: ");
scanf("%d%s",&s1.roll,s1.name);
fprintf(fp,"\n the roll no is:%d \t the name is %s",s1.roll,s1.name);
printf("\n do u wish to add new records(Y\N): ");
reply=getch();
}while(reply=='Y');
fclose(fp);
}
void read_file()
{
fp=fopen("student.txt","w");
if(fp==NULL)
{
printf("\n the file cannot be opened");
exit(1);
}
while(!feof(fp))
{
fscanf(fp,"%d%s",&s1.roll,s1.name);
printf("\n roll no=%d\tname=%s",s1.roll,s1.name);
}
fclose(fp);
}
0