#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Student
{
int id;
int grade;
};
struct Student john;
int main()
{
john.id = 100;
john.grade = 80;
struct Student steve;
fwrite(&john, sizeof(struct Student), 1, stdout);
fread(&steve, sizeof(struct Student), 1, stdout);
printf("\n%d %d \n", steve.id, steve.grade);
return 0;
}
I am trying to write a struct
into a file(in this case it is stdout), then I am trying to read it.
The values it prints are random, what could be the reason?