Hi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.
float in C structures
Collapse
X
-
Tags: None
-
have a look at this tutorial on Data StructuresOriginally posted by vandanasridharHi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.
http://www.cplusplus.c om/doc/tutorial/structures.htmlComment
-
hello ji,Originally posted by chellaHi Vandana,
The question seems to be generic. It would be useful to suggest when it is more specific.
Actually i wanna write a program who can accept data of 10 players and sort them and display result team wise. when i started i write code to scan details.
but it gives message at runtime while entering first floating value that floating point formats not linked abnormal program termination.
i m sending my code of program
Code:#include<stdio.h> #include<conio.h> #include<string.h> struct player_detail { char player_name[15]; char team_name[15]; float batting_avg; }players[10]; void main() { int i,x; for(i=0;i<3;i++) { printf("\nEnter Player Name : "); gets(players[i].player_name); printf("\nEnter Team : "); gets(players[i].team_name); printf("\nEnter Batting Average : "); scanf("%f",&players[i].batting_avg); } }Comment
-
this is a problem with Visual C where it does not load floating point support if it does not think it necessary, see
http://msdn2.microsoft .com/en-us/library/k1x26e0x.aspx
try putting a dummy floating point assignment in the program to force loading of the support, e.g.
Code:int main() { int i,x; float z=10.0f;Comment
-
Originally posted by horace1this is a problem with Visual C where it does not load floating point support if it does not think it necessary, see
http://msdn2.microsoft .com/en-us/library/k1x26e0x.aspx
try putting a dummy floating point assignment in the program to force loading of the support, e.g.
Code:int main() { int i,x; float z=10.0f;
Hi,
i m using C++ compiler of versoin 3.0. & this is also giving the same Problem.
Will u please tell me how i can use float in structures while using same compiler.Comment
-
did you try defining a float to force loading of the libraries? e.g.Originally posted by vandanasridharHi,
i m using C++ compiler of versoin 3.0. & this is also giving the same Problem.
Will u please tell me how i can use float in structures while using same compiler.
is it Visual C++ V3.0 or another compiler?Code:int main() { int i,x; float z=10.0f;Comment
-
it is turbo c++.Originally posted by horace1did you try defining a float to force loading of the libraries? e.g.
is it Visual C++ V3.0 or another compiler?Code:int main() { int i,x; float z=10.0f;Comment
-
it appears in Turbo C V3.0 you have to force loading of the floating point conversions, seeOriginally posted by vandanasridharit is turbo c++.
http://www.vmlinux.org/~jakov/community.borla nd.com/15204.html
it recommends that you include the following function in your code - you don't need to to call it
Code:static void force_fpf() { float x, *y; /* Just declares two variables */ y = &x; /* Forces linkage of FP formats */ x = *y; /* Suppress warning message about x */ }Comment
-
Thx ur advice works. thx again for sending this article.Originally posted by horace1it appears in Turbo C V3.0 you have to force loading of the floating point conversions, see
http://www.vmlinux.org/~jakov/community.borla nd.com/15204.html
it recommends that you include the following function in your code - you don't need to to call it
Code:static void force_fpf() { float x, *y; /* Just declares two variables */ y = &x; /* Forces linkage of FP formats */ x = *y; /* Suppress warning message about x */ }Comment
-
vandanasridhar hiOriginally posted by vandanasridharHi,
i m using C++ compiler of versoin 3.0. & this is also giving the same Problem.
Will u please tell me how i can use float in structures while using same compiler.
I have the problem to.it was simple just use a dumi float variable out of the structure then assign the value and use the variable;
struct dum{
int a;
float f;
----------
---------
};
int dum_f = f ;Comment
-
float values in c structures
Hi Vandana
Don't worry
There is simple solution for ur problem when getting the error
"scanf : floating point formats not linked
Abnormal program termination"
just add the two given lines in ur program
extern void _floatconvert() ;
#pragma extref _floatconvert
and enjoy it
one example code is given
Code:#include<stdio.h> extern void _floatconvert(); #pragma extref _floatconvert struct stud { char name[50]; float m1, m2, m3, total; }s[10]; void main() { int n,i; clrscr(); printf("How many students? \t"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\nGive name of student%d:\t",i+1); scanf("%s",s[i].name); printf("\nGive 3 marks of %s\t",s[i].name); scanf("%f%f%f",&s[i].m1,&s[i].m2,&s[i].m3); s[i].total = s[i].m1 + s[i].m2 + s[i].m3; } printf("\nNAME\t\tMARK1\tMARK2\tMARK3\tTOTAL"); for(i=0;i<n;i++) { printf("\n%s\t\t%0.2f\t%0.2f\t%0.2f\t%0.2f",s[i].name, s[i].m1, s[i].m2, s[i].m3, s[i].total); } }Comment
Comment