C program to write structure values in file and read it back into another structure from the same file
#include<stdio.h>
struct Student {
char roll[5];
char name[12];
char percent[5];
char space;
} s1 = { "10",
"SMJC", "80", ' '};
int main() {
FILE *fp;
struct Student s2;
//Write details of
s1 to file
fp =
fopen("ip.txt", "w");
fwrite(&s1,
sizeof(s1), 1, fp);
fclose(fp);
fp =
fopen("ip.txt", "r");
fread(&s2,
sizeof(s2), 1, fp);
fclose(fp);
printf("\nRoll : %s", s2.roll);
printf("\nName : %s", s2.name);
printf("\nPercent : %s\n", s2.percent);
return (0);
}