ok, this is my final program:
PHP Code:
#include<stdio.h>
//-------------------------------------
struct data
{
int id;
int gpa;
};
//-------------------------------------
//-------------------------------------
void readrec(struct data *r)
{
printf("\n Enter the ID No: ");
scanf("%d",&r->id);
printf("\n Enter the GPA: ");
scanf("%d",&r->gpa);
}
//-------------------------------------
main()
{
FILE *fp;
struct data r;
int ch=0;
fp=fopen("struct.txt","ab");
printf("\n Enter (1)to write. (0)to EXIT.");
scanf("%d",&ch);
while(ch!=0)
{
readrec(&r);
fwrite(&r,sizeof(struct data),1,fp);
fprintf(fp,"\n");
printf("\n Enter (1)to write. (0)to EXIT.");
scanf("%d",&ch);
}
fclose(fp);
fp=fopen("struct.txt","rb");
while(!feof(fp))
{
fread(&r,sizeof(struct data),1,fp);
printf("\nID:%d\t\tGPA:%d",r.id,r.gpa);
}
fclose(fp);
}
when i input
id:1 gpa:1
the out put is
id:1 gpa:1
id:10 gpa:1
that what is in the file struct.txt----> ( ).