I have written the records in the file using following way.
#include <stdio.h>
#include <string.h>
#include <malloc.h>
#define DSZ 108
struct stud
{
char name[100];
int roll_no;
};
struct student
{
struct stud s;
int grade;
}value;
int main() {
FILE *fps;
struct student *buffer=(struct student*)malloc(sizeof(struct s
+tudent));
int n,j;
fps=fopen("Myfile","wb+");
value.s.roll_no=149;
value.grade=1;
strcpy(value.s.name,"myname");
n=fwrite(&value,DSZ,1,fps);
rewind(fps);
n=fread(buffer,DSZ,1,fps);
printf("Name:%s Grade:%d NO:%d\n",buffer->s.name,buffer->grade
+,buffer->s.roll_no);
fclose(fps);
}
|