Thread: can you tell me why2?

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    24

    can you tell me why2?

    Code:
    #include <stdio.h>
    #include <malloc.h>
    
    struct student
    {
    float	score;
    };
    main()
    {
    	struct  student  *p;
    
    	p=(struct student *)malloc(sizeof(struct student));
    	scanf("%f",&(p->score));
            /* or instead of "scanf("%f",&(*p).score);" */
    	printf("%f\n",(*p).score);
    }
    why once i run the programme
    It will display :
    scanf : floating point formats not linked
    Abnormal program termination


    can you tell me why ???waiting............

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    1) Don't use malloc.h. Use stdlib.h.
    2) Don't cast the return of malloc.
    3) Your compiler apparently doesn't support floating point numbers. Get a new one.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    This?
    Last edited by Dave_Sinkula; 02-16-2005 at 09:05 PM.
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  4. #4
    Registered User
    Join Date
    Aug 2004
    Posts
    4
    I too, come across the same problem earlier, In some older compliers this problem may arise.
    It can be overcome by intialising the Floating Point emulator in your code as:

    extern void _floatconvert( );
    #pragma extref _floatconvert

    Thanx,Gobinath

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Here's a tip - paste error messages into google.
    http://www.google.co.uk/search?q=flo...ats+not+linked
    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