A simple yet a valid question...

This is a discussion on A simple yet a valid question... within the C Programming forums, part of the General Programming Boards category; Hello, Please tell me why can't i use a float variable in structure?? for eg.. Code: struct Point { float ...

  1. #1
    Registered User
    Join Date
    Jan 2008
    Posts
    225

    A simple yet a valid question...

    Hello,
    Please tell me why can't i use a float variable in structure??

    for eg..
    Code:
    struct Point
    {
        float x;
        float y;
    };
    Now when i use this structure and take variable input using scanf, it gives error " Floating Point Format Not Linked"
    and then without taking any input it displays message "Abnormal Program Termination" and exits.

    Please tell why is this happening and also it's solution

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,941
    Please tell me why can't i use a float variable in structure??
    But you can.

    Now when i use this structure and take variable input using scanf, it gives error " Floating Point Format Not Linked"
    and then without taking any input it displays message "Abnormal Program Termination" and exits.
    Perhaps you are using it wrongly. Post the smallest and simplest program that demonstrates the error.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Code:
    struct Point
    {
        float x;
        float y;
    };
    
    int main() {
        struct Point p;
        scanf("%f",&(p.x));
    }
    This should compile. Maybe you are missing the struct keyword in front of Point p;? Maybe you are doing scanf("%f",p)?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    My bet would be that you are using Turbo C or some other ancient compiler. In old times, processors were not always able to use floating point, and the additional library for floating point in C was quite large, the compiler would have one set of "integer library" and another "floating point library".

    You need to read the help for your compiler to see what you should enable to get your floating point included.

    However, the other question would be why you are not using a more modern compiler.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Perhaps i didn't convey my problem correctly. Actually problem only occurs when you define an array of struture which contains only float values. Here's a small example for that

    Code:
    #include <stdio.h>
    
    struct points
    {
      float x;
      float y;
    };
    
    int main(void)
    {
      struct points p[20];
      int vertices,i;
    
     printf("\n\nEnter The Number Of Vertices :");
     scanf("&#37;d",&vertices);
     for(i=0;i<vertices;i++)
     {
    	printf("\n\nEnter The %d th Point :",i+1);
    	scanf("%f %f",&p[i].x,&p[i].y);
     }
    
     return 0;
    }

  6. #6
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Yeah matsp, you are correct ( as usual). I am using ancient Turbo C++ 3.0 compiler

  7. #7
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,941
    I compiled (MinGW port of gcc 3.4.5) and ran your program with no problems.

    What compiler are you using?

    EDIT:
    Ah.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Some googling comes up with this:
    http://www.jeffc.org/msdos/dos-faq.html#Q0304

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    Thanks Mats!!
    Now it's working fine

  10. #10
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,791
    Any reason you can't switch compiler?
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #11
    Registered User
    Join Date
    Sep 2008
    Location
    Toronto, Canada
    Posts
    1,832
    Oh I remember the days you had to force the linker to include the math library. Even switches on whether to in-line 387 code or call an emulation library, or thirdly, to include auto-detect of the target machine if you're not sure if it had floating point support.

    Life was simpler back then. (Well, yeah, it was, because I understood why things were the way the were.

  12. #12
    Registered User
    Join Date
    Jan 2008
    Posts
    225
    The reason is in my college it's the same compiler since last 10 years and i brought the compiler from my college and therefore i use that compiler!when i finish college i will plan to use a better compiler
    As such my job is done on this compiler too

  13. #13
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    > Oh I remember the days you had to force the linker to include the math library
    Those days haven't gone anywhere

  14. #14
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,791
    Quote Originally Posted by chottachatri View Post
    The reason is in my college it's the same compiler since last 10 years and i brought the compiler from my college and therefore i use that compiler!when i finish college i will plan to use a better compiler
    As such my job is done on this compiler too
    It doesn't need to be.
    They scammed you when they sold you that compiler. They took money for something that can be found for free, and it isn't even standards compliant to boot.
    My suggestion: dump it and get a better one. Right now.
    Doesn't matter if you bought it or not.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Simple class question
    By 99atlantic in forum C++ Programming
    Replies: 6
    Last Post: 04-20-2005, 11:41 PM
  2. Simple question about pausing program
    By Noid in forum C Programming
    Replies: 14
    Last Post: 04-02-2005, 08:46 AM
  3. simple question.
    By InvariantLoop in forum Windows Programming
    Replies: 4
    Last Post: 01-31-2005, 11:15 AM
  4. simple scope question
    By 7stud in forum C++ Programming
    Replies: 18
    Last Post: 01-30-2005, 06:45 AM
  5. simple fgets question
    By theweirdo in forum C Programming
    Replies: 7
    Last Post: 01-27-2002, 05:58 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21