You are here:

C/Floating point in Structure

Advertisement


Question
I have a problem regarding the floating point. If I used arrays as floating point it accept. for ex- float a[5];
    But when I defined floating point array inside the structure and used scanf it gives an error scanf :floating point formats not linked
If I initialize the structure then the member variable which I had declared as floating point it accepts.
But while using scanf it doesn't. Will you please help me in this regard. I am using Turbo C compiler.


for ex :
 typedef struct{
                char name[10];
                  int age;
                  float percentage[5];}student;

main()
{
   student s[3];
 for (i=0;i<3;i++)
    { printf("%f",a[i]);}
}




if I initialize as
student s[3]={{"Ram",23,34.5},
              {"Rama",21,25.6},
               {"Ravi",20,65.7}};
 Then the value of floating point is accepted and it display without any error.
Expect the proper guidance from you.

Thanks in anticipation
Meenakshi  

Answer
Hi,

   Your problem is not clear to me. It looks like, you are getting compilation errors for a statement which is reading array. If you show me the code that gave you error, then I can suggest something. Do post the code, for which you got compilation error.

-ssnkumar

C

All Answers


Answers by Expert:


Ask Experts

Volunteer


Narendra

Expertise

I can answer questions in C related to programming, data structures, pointers and file manipulation. I use Solaris for doing C code and if you have questions related to C programming on Solaris, I will be able to help better.

Experience

6.5

Organizations belong to
Sun Microsystems

Awards and Honors
Brain Bench Certified Expert C programmer.
Advanced System Software Certified

©2012 About.com, a part of The New York Times Company. All rights reserved.