scanf: floating point format not linked
Solution 1
This issue is most likely seen when using Turbo C/ Borland C compilers. These compilers do not link in the floating-point (f-p) library unless we need it. Therefore, by force we need to add any floating-point (f-p) function when we have "%f"
or other floating point (f-p) formats in scanf()
or printf()
calls.
To fix this error, call a floating-point (f-p) function or just add link of a file, which contains at least one floating-point (f-p) function. eg.
void dummy(float *a) {
float b=*a; //perform some floating access
dummy (&b); //calling a floating point function
}
Solution 2
Solution 1:
According to the following link: http://docs.embarcadero.com/products/rad_studio/radstudio2007/RS2007_helpupdates/HUpdate4/EN/html/devwin32/rte_printf_scanf_float_not_linked_xml.html
you can add following code to one source module (and it worked for me):
extern _floatconvert;
#pragma extref _floatconvert
Example:
#include<....>
.............
extern _floatconvert;
#pragma extref _floatconvert
int main(){......}
..........
..........
Solution 2:
Add the following dummy function in source code:
void dummy()
{
float f,*fp;
fp=&f;
}
Solution 3
Floating-point formats contain formatting information that is used to manipulate floating-point numbers in certain runtime library functions, such as scanf() and atof(). Typically, you should avoid linking the floating-point formats (which take up about 1K) unless they are required by your application. However, you must explicitly link the floating-point formats for programs that manipulate fields in a limited and specific way.
Refer to the following list of potential causes (listed from most common to least common) to determine how to resolve this error:
CAUSE: Floating point set to None. You set the floating-point option to None when it should be set to either Fast or Normal.
FIX: Set Floating Point to Fast or Normal.
CAUSE: Either the compiler is over-optimizing or the floating-point formats really do need to be linked. You need the floating-point formats if your program manipulates floats in a limited and specific way. Under certain conditions, the compiler will ignore floating-point usage in scanf(). For example, this may occur when trying to read data into a float variable that is part of an array contained in a structure.
FIX: Add the following code to one source module:
SOLUTION: Just add the following function in your program. It will force the compiler to include required libraries for handling floating point linkages.
static void force_fpf() /* A dummy function */
{
float x, *y; /* Just declares two variables */
y = &x; /* Forces linkage of FP formats */
x = *y; /* Suppress warning message about x */
}
dnyan86
Updated on October 23, 2022Comments
-
dnyan86 over 1 year
I'm getting error scanf: floating point format not linked while reading value for 'info'of following structure.
struct node { float info; struct node *next; }*start;
in main()
void main() { struct node *temp; temp = (struct node*)malloc(sizeof(struct node)); printf("enter data = "); scanf("%f",&temp->info); }
its not reading any value for that scanf and coming out of program.
How to get around this ?