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 1 of 3.

Pratyush sharma said:   3 years ago
According to the GCC compiler, this program is right having no error, and it will scan you 9 entries of name and 9 entries of salary. Hope you got it.
(1)

Ratan Lal said:   9 years ago
In GCC it will run correctly.

Trupti said:   10 years ago
Program is right. No error and no output.

Deepak Hirapur said:   10 years ago
It executed successfully in GCC.

Ankit ardeshana said:   10 years ago
I have run this program with GCC. It executed successfully.

Shivani said:   10 years ago
Its necessary to use address operator while taking the input by using scanf() except with %s.

Shivani said:   10 years ago
It is also supported with turbo C.

Anusha said:   1 decade ago
Kindly wish to all. Please tell me why it is linked error?

Rrk said:   1 decade ago
I agree with you Sanjeev. But in the question scanf is used.

Sanjeev said:   1 decade ago
&e[i].sal will return an address which is an int and we are using %f in printf to print this is the reason for having floating point format not linked error.


Post your comments here:

Your comments will be displayed after verification.