473,386 Members | 1,973 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

float in C structures

Hi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.
Mar 2 '07 #1
12 13834
chella
51
Hi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.

Hi Vandana,
The question seems to be generic. It would be useful to suggest when it is more specific.
Mar 2 '07 #2
horace1
1,510 Expert 1GB
Hi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.
have a look at this tutorial on Data Structures
http://www.cplusplus.com/doc/tutorial/structures.html
Mar 2 '07 #3
Hi Vandana,
The question seems to be generic. It would be useful to suggest when it is more specific.
hello ji,
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
Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. struct player_detail
  5. {
  6.     char player_name[15];
  7.     char team_name[15];
  8.     float batting_avg;
  9. }players[10];
  10. void main()
  11. {
  12.     int i,x;
  13.     for(i=0;i<3;i++)
  14.     {
  15.         printf("\nEnter Player Name : ");
  16.         gets(players[i].player_name);
  17.         printf("\nEnter Team : ");
  18.         gets(players[i].team_name);
  19.         printf("\nEnter Batting Average : ");
  20.         scanf("%f",&players[i].batting_avg);
  21.     }
  22. }
Mar 3 '07 #4
horace1
1,510 Expert 1GB
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.
Expand|Select|Wrap|Line Numbers
  1. int  main()
  2. {
  3.     int i,x;
  4.     float z=10.0f;
  5.  
Mar 3 '07 #5
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.
Expand|Select|Wrap|Line Numbers
  1. int  main()
  2. {
  3.     int i,x;
  4.     float z=10.0f;
  5.  

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.
Mar 14 '07 #6
horace1
1,510 Expert 1GB
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.
did you try defining a float to force loading of the libraries? e.g.
Expand|Select|Wrap|Line Numbers
  1. int  main()
  2. {
  3.     int i,x;
  4.     float z=10.0f;
is it Visual C++ V3.0 or another compiler?
Mar 14 '07 #7
did you try defining a float to force loading of the libraries? e.g.
Expand|Select|Wrap|Line Numbers
  1. int  main()
  2. {
  3.     int i,x;
  4.     float z=10.0f;
is it Visual C++ V3.0 or another compiler?
it is turbo c++.
Mar 21 '07 #8
horace1
1,510 Expert 1GB
it is turbo c++.
it appears in Turbo C V3.0 you have to force loading of the floating point conversions, see
http://www.vmlinux.org/~jakov/community.borland.com/15204.html

it recommends that you include the following function in your code - you don't need to to call it
Expand|Select|Wrap|Line Numbers
  1.           static void force_fpf()
  2.           {
  3.               float x, *y; /* Just declares two variables */
  4.               y = &x;      /* Forces linkage of FP formats */
  5.               x = *y;      /* Suppress warning message about x */
  6.           }
  7.  
Mar 21 '07 #9
it appears in Turbo C V3.0 you have to force loading of the floating point conversions, see
http://www.vmlinux.org/~jakov/community.borland.com/15204.html

it recommends that you include the following function in your code - you don't need to to call it
Expand|Select|Wrap|Line Numbers
  1.           static void force_fpf()
  2.           {
  3.               float x, *y; /* Just declares two variables */
  4.               y = &x;      /* Forces linkage of FP formats */
  5.               x = *y;      /* Suppress warning message about x */
  6.           }
  7.  
Thx ur advice works. thx again for sending this article.
Mar 23 '07 #10
rifat
2
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.
vandanasridhar hi
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 ;
Mar 23 '07 #11
@vandanasridhar
try including <float.h> header file
Oct 1 '11 #12
@vandanasridhar

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


Expand|Select|Wrap|Line Numbers
  1. #include<stdio.h>
  2.  
  3.  
  4. extern void _floatconvert();
  5. #pragma extref _floatconvert
  6.  
  7.  
  8.  
  9. struct stud
  10. {     char name[50];
  11.     float m1, m2, m3, total;
  12. }s[10];
  13. void main()
  14. {
  15.     int n,i;
  16.     clrscr();
  17.     printf("How many students? \t");
  18.     scanf("%d",&n);
  19.     for(i=0;i<n;i++)
  20.     {
  21.         printf("\nGive name of student%d:\t",i+1);
  22.         scanf("%s",s[i].name);
  23.         printf("\nGive 3  marks of %s\t",s[i].name);
  24.         scanf("%f%f%f",&s[i].m1,&s[i].m2,&s[i].m3);
  25.         s[i].total = s[i].m1 + s[i].m2 + s[i].m3;
  26.     }
  27.     printf("\nNAME\t\tMARK1\tMARK2\tMARK3\tTOTAL");
  28.     for(i=0;i<n;i++)
  29.     {
  30.         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);
  31.     }
  32. }
  33.  
Apr 26 '12 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Bernard Delmée | last post by:
Is there a simple way to modify the default sprintf mask used for floats ? (eg something like sys.float_mask = '%.2f') I've tried assigning to float.__dict__, but that's apparently not allowed.
1
by: kazack | last post by:
Hi all it's me again with another question as I got further in my book. The chapter I am in covers structres, abstract data and classes. I only read through to the end of the coverage on...
1
by: Maciej | last post by:
Hello I have some problems with converting varbinary to float in T-SQL stored procedure. In my C# application i have table of structures with double type fields. Size of this table is variant. I...
6
by: Ken Allen | last post by:
OK, I admit that I have been programming since before C++ was invented, and I have developed more than my share of assembly language systems, and even contributed to operating system and compiler...
14
by: pmclinn | last post by:
I've noticed that many programmers use classes to store data about such things like: Class Customers .....Phone ....ID ....Address End Class....
6
by: ljlevend2 | last post by:
I need to create TypeConverters for the floating type drawing structures (i.e., PointF, SizeF and RectangleF) that behave exactly as their integer couterparts (e.g., System.Drawing.PointConverter)....
2
by: thomasfarrow | last post by:
At work, our development team has a development standards document that insists Structures should never be used. I'm looking to change this standard but need a suitable argument in order to make...
45
by: Carramba | last post by:
Hi! I now that I can't do straight forward any bitwise operation on float (double etc..). But I wondering what is the easiest/best way to do this? I was thinking if I have float x=1.1111 so I can...
4
by: durgavaraprasad | last post by:
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" ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.