Hi I'm prasad.
I am new to structures in C.
I declared a structure as follows.
But it is giving a run-time error that
"scanf: floating point formats not matched
Abnormal program termination" at the line indicated.
Some of my friends told me that we can't access floating point variables in structures directly. We need the help of certain functions. Is it true? If so how to access them?
#include<stdio. h>
#include<conio. h>
#include<alloc. h>
struct struct1
{
int eno;
char ename[20];
float sal;
};
int main()
{
struct struct1 *p;
clrscr();
p=malloc(sizeof (struct struct1)*1);
printf("Enter employee number: ");
scanf("%d",&(*p ).eno);
printf("Enter employee name: ");
scanf("%s",(*p) .ename);
printf("Enter employee salary: ");
fflush(stdin);
scanf("%f",&(*p ).sal);
printf("NUMBER: %d\n",(*p).eno) ;
printf("NAME: %s\n",(*p).enam e);
printf("SALARY: %0.1f\n",(*p).s al);
return 1;
}
Please help me. Thanks in advance.
I am new to structures in C.
I declared a structure as follows.
But it is giving a run-time error that
"scanf: floating point formats not matched
Abnormal program termination" at the line indicated.
Some of my friends told me that we can't access floating point variables in structures directly. We need the help of certain functions. Is it true? If so how to access them?
#include<stdio. h>
#include<conio. h>
#include<alloc. h>
struct struct1
{
int eno;
char ename[20];
float sal;
};
int main()
{
struct struct1 *p;
clrscr();
p=malloc(sizeof (struct struct1)*1);
printf("Enter employee number: ");
scanf("%d",&(*p ).eno);
printf("Enter employee name: ");
scanf("%s",(*p) .ename);
printf("Enter employee salary: ");
fflush(stdin);
scanf("%f",&(*p ).sal);
printf("NUMBER: %d\n",(*p).eno) ;
printf("NAME: %s\n",(*p).enam e);
printf("SALARY: %0.1f\n",(*p).s al);
return 1;
}
Please help me. Thanks in advance.
Comment