C Programming - Structures, Unions, Enums - Discussion
Discussion Forum : Structures, Unions, Enums - Point Out Errors (Q.No. 5)
5.
Point out the error in the program?
#include<stdio.h>
int main()
{
struct emp
{
char name[20];
float sal;
};
struct emp e[10];
int i;
for(i=0; i<=9; i++)
scanf("%s %f", e[i].name, &e[i].sal);
return 0;
}
Answer: Option
Explanation:
At run time it will show an error then program will be terminated.
Sample output: Turbo C (Windows)
c:\>myprogram Sample 12.123 scanf : floating point formats not linked Abnormal program termination
Discussion:
27 comments Page 2 of 3.
Prakash said:
1 decade ago
Did it in gcc? float value is changed?
Input-vector
22.6245.
Output- vector
0.0022.6245 0.00..
Input-vector
22.6245.
Output- vector
0.0022.6245 0.00..
Markpravo said:
1 decade ago
Floating format not linked ?
Rohit said:
1 decade ago
The pgm will work 100% correctly. There is no prob of linker.
Kumarachary said:
1 decade ago
void linkfloat(float *p)
{
float a=0,*b;
b=&a;
a=*b;
}
This code causes emulatore to be linked and suppress the warning-variable not found.
{
float a=0,*b;
b=&a;
a=*b;
}
This code causes emulatore to be linked and suppress the warning-variable not found.
Nidhinpradeep said:
1 decade ago
Here no comma seperating %s ND % f.
So floating format is not linked.
So floating format is not linked.
Ravindra bagale said:
1 decade ago
In pc floats are computed through some hardware implementation, i.e.floating point units. When you uses array of structure which contains float values, then this error will come. This error comes because of the format of value -storage of structure.
We can remove this error by explicitly calling the floating point format linker.
Solution is- add following code in your source file, don't call it, it automatically get call when error arises.
static void forcefloat(float *p)
{
float f = *p;
forcefloat(&f);
}
We can remove this error by explicitly calling the floating point format linker.
Solution is- add following code in your source file, don't call it, it automatically get call when error arises.
static void forcefloat(float *p)
{
float f = *p;
forcefloat(&f);
}
Nagaraj said:
1 decade ago
Ya, it doesn't support float, we have to cast inoder to change it to float.
K.maheswari said:
1 decade ago
Why it dsn 't support floating points ?
Surender said:
1 decade ago
Please friend don't use Turbo C IDE/Compiler.
Its not a standard complier.
Better you use borland C++, Visual C++, GCC.
Its not a standard complier.
Better you use borland C++, Visual C++, GCC.
Rajesh Manem said:
1 decade ago
Some compilers for small machines, including Turbo C (and Ritchie's original PDP-11 compiler), leave out floating point support if it looks like it will not be needed. In particular, the non-floating-point versions of printf and scanf save space by not including code to handle %e, %f, and %g. It happens that Turbo C's heuristics for determining whether the program uses floating point are insufficient, and the programmer must sometimes insert an extra, explicit call to a floating-point library routine to force loading of floating-point support.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers