Reputation: 21
Here is a code I m currently working upon. It is related to array of structures. This program is currently working fine. But If I replace the data type of salary variable in the structure employee to float, a logical error arises. I cannot enter the salary value while scanf.Even if I change the format specifier, the problem persists.
Can anybody locate the error and how would it be resolved?
#include<stdio.h>
#include<conio.h>
struct employee
{
int emp_no;
char emp_name[25];
int salary;
};
void main()
{
struct employee emp[2];
int i;
clrscr();
for(i=0;i<2;i++)
{
printf("enter details for employee #%d:\n",(i+1));
printf("code:");
scanf("%d",&emp[i].emp_no);
printf("name:");
scanf("%s",emp[i].emp_name);
printf("salary:");
scanf("%d",&emp[i].salary);
}
printf("\n");
for(i=0;i<2;i++)
{
printf("details of employee #%d are:\n", (i+1));
printf("code: %d\n", emp[i].emp_no);
printf("name: %s\n", emp[i].emp_name);
printf("salary: %d\n", emp[i].salary);
}
getch();
}
Upvotes: 0
Views: 192
Reputation: 1471
Just include this function after your main function:
static void force_fpf(){
float x,*y;
y=&x;
x=*y;
}
This will run your program successfully
Upvotes: 1
Reputation: 783
http://c-faq.com/fp/fpnotlinked.html
Your compiler is optimizing the output binary size and is not linking with floating point formatting. Check your compiler/linker settings.
Upvotes: 2