Thread: C Structure

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    C Structure

    I have a C-program based on Structure as shown below;
    but when I try to run It ;it is accepting "value for page" but
    at time of accepting "value for price" it is giving me an error as:
    "scanf: floating point not linked. Abnormal program termination"
    what should I do to salve this problem ?

    Code:
    #include<stdio.h>
    #include<conio.h>
    struct book
    {
    int page;
    float price;    
    }b[3];
    void main()
    {
    clrscr();
    printf("\nEnter pages & prices:\n");
    for(int i=0;i<3;i++)
    {
    scanf("%d",&b[i].page);
    scanf("%f",&b[i].price);
    printf("\npages=%d    price=%f\n",b[i].page,b[i].price);
    }
    }

  2. #2
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    its working just fine,,,,,,, sample run

    enter pages and price:
    23
    33.45

    pages=23 price=33.45001
    34
    44.4

    pages=34 price=44.400000


    and so on
    Last edited by qqqqxxxx; 03-14-2006 at 01:40 AM.

  3. #3
    Its hard... But im here swgh's Avatar
    Join Date
    Apr 2005
    Location
    England
    Posts
    1,688
    There is no end to your structure, you are missing the terminating brace. It should be this:

    Code:
    struct book
    {
    int page;
    float price;
    int b[3];  // this i am guessing is an int type as you used %d to declare it
    };           // you need this at the end of a struct
    Remember to place the temintating brace with semi-colon on a new line.
    Never mix it in with data members like in your post - this can lead to problems!

  4. #4
    Registered User
    Join Date
    Feb 2006
    Posts
    155
    he is declaring an array of structures there.

  5. #5
    Just kidding.... fnoyan's Avatar
    Join Date
    Jun 2003
    Location
    Still in the egg
    Posts
    275
    And , I suggeest you to use int main() and return at the end of your program. You may want to
    have a look

    http://c-faq.com/ansi/index.html

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > scanf: floating point not linked
    Your compiler is from the stone age, and it can't tell all the time whether you're using float or not (back in the days when float was an expensive library function rather than on-chip).
    http://c-faq.com/fp/fpnotlinked.html
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  7. #7
    C/C++ homeyg's Avatar
    Join Date
    Nov 2004
    Location
    Louisiana, USA
    Posts
    209
    Quote Originally Posted by swgh
    There is no end to your structure, you are missing the terminating brace. It should be this:

    Code:
    struct book
    {
    int page;
    float price;
    int b[3];  // this i am guessing is an int type as you used %d to declare it
    };           // you need this at the end of a struct
    Remember to place the temintating brace with semi-colon on a new line.
    Never mix it in with data members like in your post - this can lead to problems!
    Code:
    struct book
    {
    int page;
    float price;
    }b[3];
    This is correct. It's just the sytax for declaring objects of the struct immediately.

  8. #8
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    Thanks For Quick reply...
    I am using Turbo C & I Want to salve this Structure problem
    I am still not getting o/p
    Is there any other way to overcome this problem

  9. #9
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,665
    > Is there any other way to overcome this problem
    So did you get past the "floating point not linked" and are now onto some other problem?

    Post your latest code if you've made edits.

    Oh, and main returns int, not void.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem referencing structure elements by pointer
    By trillianjedi in forum C Programming
    Replies: 19
    Last Post: 06-13-2008, 05:46 PM
  2. Replies: 5
    Last Post: 02-14-2006, 09:04 AM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Serial Communications in C
    By ExDigit in forum Windows Programming
    Replies: 7
    Last Post: 01-09-2002, 10:52 AM
  5. C structure within structure problem, need help
    By Unregistered in forum C Programming
    Replies: 5
    Last Post: 11-30-2001, 05:48 PM