P
prashant.khade1623
Hi
I am trying ti write a structure to a file, but I am getting
segmentation fault. Below is my program
#include<stdio.h>
main()
{
FILE *fp;
struct student {
int age;
char name[19];
char school[15];
};
struct student s1={25,"khade","KVOFPM"};
struct student s2={25,"khade","KVOFPM"};
fp = fopen("khade","r+");
fwrite(&s1,sizeof(struct student ),1,fp);
fwrite(&s2,sizeof(struct student ),1,fp);
}
Can you tell me why I am getting the error.
Also I want to read from the file. how can I do that ?
Thanks in advance
I am trying ti write a structure to a file, but I am getting
segmentation fault. Below is my program
#include<stdio.h>
main()
{
FILE *fp;
struct student {
int age;
char name[19];
char school[15];
};
struct student s1={25,"khade","KVOFPM"};
struct student s2={25,"khade","KVOFPM"};
fp = fopen("khade","r+");
fwrite(&s1,sizeof(struct student ),1,fp);
fwrite(&s2,sizeof(struct student ),1,fp);
}
Can you tell me why I am getting the error.
Also I want to read from the file. how can I do that ?
Thanks in advance