I have a structure like this
struct employeeRec{
char employeeCode[20];
char employeename[50];
int salaryLevel;
float salaryRate;
};
and in one of my conditions to input data on a structure, I did this. This includes writing it on a file.
printf("Enter the Employee Code:\n");
scanf("%s",emp.employeeCode);
fflush(stdin);
printf("Enter the Employee Name\n");
scanf ("%[^\n]%*c", emp.employeename);
fflush(stdin);
printf("Enter the Salary Level:\n");
scanf("%d", &emp.salaryLevel);
printf("Enter the Salary Rate:\n");
scanf("%f", &emp.salaryRate);
...
fwrite(&emp,sizeof(emp),1,fp);
But when I try to read the file
printf("Employee Name: %s\n",emp.employeeCode);
printf("Employee Code: %s\n",emp.employeename);
printf("Salary Level: %d\n",emp.salaryLevel);
printf("Salary Rate: $ %f/day\n", emp.salaryRate);
Employee Name, Employee Code displays. But in my Salary rate, it only displays $0.0000000
I tried putting a printf
right after the scanf
during the inputting of salary rate and correct value appears. But it is during the reading of the file that the value becomes $0.0000000