can you tell me why2?

This is a discussion on can you tell me why2? within the C Programming forums, part of the General Programming Boards category; Code: #include <stdio.h> #include <malloc.h> struct student { float score; }; main() { struct student *p; p=(struct student *)malloc(sizeof(struct student)); ...

  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,006
    This?
    Last edited by Dave_Sinkula; 02-16-2005 at 08: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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Popular pages Recent additions subscribe to a feed

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