-
structure with array
It don't get the float value?
i don't know what happens?
Code:
# include<stdio.h>
struct pay
{
int id;
char name[20];
float rate;
};
void main()
{
struct pay emp[5];
int i;
clrscr();
for(i=0;i<5;++i)
{
scanf("%d",&emp[i].id);
scanf("%s",&emp[i].name);
scanf("%f",&emp[i].rate);
}
for(i=0;i<5;++i)
{
printf("\n%d\t",emp[i].id);
printf("%s\t",emp[i].name);
printf("%f",emp[i].rate);
}
printf("\n");
}
-
Works okay for me, what's your input like?
-
it return the error
scanf don't get float linking
abnormal program termination.
-
I've heard about this problem, if it's what it sounds like, either get a newer compiler or check the manual for a workaround. I think the workaround is something like this
Code:
# include<stdio.h>
struct pay
{
int id;
char name[20];
float rate;
};
linkfloat(float *fp){
/*DON"T CALL!*/
float f = *fp;
linkfloat(&f);
}
void main()
{
struct pay emp[5];
int i;
clrscr();
for(i=0;i<5;++i)
{
scanf("%d",&emp[i].id);
scanf("%s",&emp[i].name);
scanf("%f",&emp[i].rate);
}
for(i=0;i<5;++i)
{
printf("\n%d\t",emp[i].id);
printf("%s\t",emp[i].name);
printf("%f",emp[i].rate);
}
printf("\n");
}
-
[B]It's works!!!!
THANX Pioneer THANX !!!
-
>>void main()
No, it's int main(void) and return 0; at the end.
>>scanf("%s", ....
I'd advise against using scanf() to read strings. it does no length validation. Lookup fgets() instead, but be warned that scanf() will leave input in the buffer that will cause problems with fgets(), so you need to be a bit careful if you use both in the same program. ;)
>>clrscr();
This is a non-standard function, and will probably come in a non-standard header file (conio.h maybe) which you don't appear to have included.