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;
}
Error: invalid structure member
Error: Floating point formats not linked
No error
None of above
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 3 of 3.

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.

Abhinandan said:   1 decade ago
The program runs fine when float is changed to int, can't get whats the problem with float.

Waiting for an answer.

Shivam said:   1 decade ago
Please tell me why this error occurs?

Venkatesh said:   1 decade ago
Hi all,

What does "Floating point formats not linked, abnormal program termination mean" ?

Does it mean the usage of data type is being decided by the compiler rather than the user?

Sowmya said:   1 decade ago
But how does a linker error occur??

Ram said:   1 decade ago
Hi preethi its linking error yaar.

Novice_user said:   1 decade ago
When run with gcc it shows no error and the program runs fine.
Why there is linking problem in Turbo C??


Post your comments here:

Your comments will be displayed after verification.