Probelm_1 : Make a program that receives the employee's name, ID, age, and salary on the keyboard and stores them in the binary file expire.bin However, employee information should be expressed in structure, name is defined as a string, and the rest of the information is defined as an integer. And it is estimated that the number of inputs is unknown.
Contents to enter (currently, the number of employees is 6, but the program is created so that it can be stored more than that)
ex) example input:
tom 10331 21 24000000
eric 10333 23 28000000
jane 40234 26 40000000
mary 30022 46 65000000
kim 90032 25 38000000
Lee 90038 24 30000000
After that, Write a program that reads the contents of the employment.bin file generated in question 1 and outputs it to the screen.
and I wrote a simple code about only one input but, it didn't work,, Can you explain why this program doesn't work?
#include <stdio.h>
typedef struct{
char *name;
int id, age, salary;
} Employee;
int main(){
char tmp[1000];
Employee e;
FILE* fout;
FILE* fin;
fout = fopen("employee.bin", "wb");
printf("Name, ID, age, salary: ");
scanf("%s %d %d %d", e.name, &e.id, &e.age, &e.salary);
fwrite(&e, sizeof(e), 1, fout);
fclose(fout);
fin = fopen("employee.bin", "rb");
fread(tmp, sizeof(char), 100, fin);
printf("%s",tmp);
fclose(fin);
}