I am doing a school assignment where we are to open a file, read in some information to a struct type, and do some calculations with it. The only problem I am having, is it seems that I am unable to fscanf the value 10.00 into a double type. The first code is my work, the printf's in the for loop are only there to emphasize the problem. The second code is the file I am reading from. I am absolutely clueless to the problem. Any help would be GREATLY appreciated, as this is due today.
Code:int main(void) { FILE *time; char fileName[BUFFER]; int num_employees, x, i; printf("Enter filename: "); scanf("%s", &fileName); time = fopen(fileName, "r"); fscanf(time, "%d", &num_employees); struct employee workers[num_employees-1]; for(i = 0; i < num_employees; i++) { fscanf(time, "%s", &workers[i].first); printf("%s", workers[i].first); fscanf(time, "%s", &workers[i].last); printf("%s", workers[i].last); fscanf(time, "%lf", &workers[i].payperhr); printf("%4.2f", workers[i].payperhr); } system("PAUSE"); return 0; }Code:2 John Slacker 5.15 Jane Worker 10.00



LinkBack URL
About LinkBacks


