float in C structures

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vandanasridhar
    New Member
    • Mar 2007
    • 21

    float in C structures

    Hi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.
  • chella
    New Member
    • Mar 2007
    • 51

    #2
    Originally posted by vandanasridhar
    Hi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.

    Hi Vandana,
    The question seems to be generic. It would be useful to suggest when it is more specific.

    Comment

    • horace1
      Recognized Expert Top Contributor
      • Nov 2006
      • 1510

      #3
      Originally posted by vandanasridhar
      Hi myself vandana. I wanna know how can we use float variables with in C structures. Can anyone help me.
      have a look at this tutorial on Data Structures
      http://www.cplusplus.c om/doc/tutorial/structures.html

      Comment

      • vandanasridhar
        New Member
        • Mar 2007
        • 21

        #4
        Originally posted by chella
        Hi Vandana,
        The question seems to be generic. It would be useful to suggest when it is more specific.
        hello ji,
        Actually i wanna write a program who can accept data of 10 players and sort them and display result team wise. when i started i write code to scan details.
        but it gives message at runtime while entering first floating value that floating point formats not linked abnormal program termination.

        i m sending my code of program
        Code:
        #include<stdio.h>
        #include<conio.h>
        #include<string.h>
        struct player_detail
        {
        	char player_name[15];
        	char team_name[15];
        	float batting_avg;
        }players[10];
        void main()
        {
        	int i,x;
        	for(i=0;i<3;i++)
        	{
        		printf("\nEnter Player Name : ");
        		gets(players[i].player_name);
        		printf("\nEnter Team : ");
        		gets(players[i].team_name);
        		printf("\nEnter Batting Average : ");
        		scanf("%f",&players[i].batting_avg);
        	}
        }
        Last edited by horace1; Mar 3 '07, 06:58 AM. Reason: added code tags

        Comment

        • horace1
          Recognized Expert Top Contributor
          • Nov 2006
          • 1510

          #5
          this is a problem with Visual C where it does not load floating point support if it does not think it necessary, see
          http://msdn2.microsoft .com/en-us/library/k1x26e0x.aspx

          try putting a dummy floating point assignment in the program to force loading of the support, e.g.
          Code:
          int  main()
          {
          	int i,x;
          	float z=10.0f;

          Comment

          • vandanasridhar
            New Member
            • Mar 2007
            • 21

            #6
            Originally posted by horace1
            this is a problem with Visual C where it does not load floating point support if it does not think it necessary, see
            http://msdn2.microsoft .com/en-us/library/k1x26e0x.aspx

            try putting a dummy floating point assignment in the program to force loading of the support, e.g.
            Code:
            int  main()
            {
            	int i,x;
            	float z=10.0f;

            Hi,
            i m using C++ compiler of versoin 3.0. & this is also giving the same Problem.
            Will u please tell me how i can use float in structures while using same compiler.

            Comment

            • horace1
              Recognized Expert Top Contributor
              • Nov 2006
              • 1510

              #7
              Originally posted by vandanasridhar
              Hi,
              i m using C++ compiler of versoin 3.0. & this is also giving the same Problem.
              Will u please tell me how i can use float in structures while using same compiler.
              did you try defining a float to force loading of the libraries? e.g.
              Code:
              int  main()
              {
              	int i,x;
              	float z=10.0f;
              is it Visual C++ V3.0 or another compiler?

              Comment

              • vandanasridhar
                New Member
                • Mar 2007
                • 21

                #8
                Originally posted by horace1
                did you try defining a float to force loading of the libraries? e.g.
                Code:
                int  main()
                {
                	int i,x;
                	float z=10.0f;
                is it Visual C++ V3.0 or another compiler?
                it is turbo c++.

                Comment

                • horace1
                  Recognized Expert Top Contributor
                  • Nov 2006
                  • 1510

                  #9
                  Originally posted by vandanasridhar
                  it is turbo c++.
                  it appears in Turbo C V3.0 you have to force loading of the floating point conversions, see
                  http://www.vmlinux.org/~jakov/community.borla nd.com/15204.html

                  it recommends that you include the following function in your code - you don't need to to call it
                  Code:
                            static void force_fpf()
                            {
                                float x, *y; /* Just declares two variables */
                                y = &x;      /* Forces linkage of FP formats */
                                x = *y;      /* Suppress warning message about x */
                            }

                  Comment

                  • vandanasridhar
                    New Member
                    • Mar 2007
                    • 21

                    #10
                    Originally posted by horace1
                    it appears in Turbo C V3.0 you have to force loading of the floating point conversions, see
                    http://www.vmlinux.org/~jakov/community.borla nd.com/15204.html

                    it recommends that you include the following function in your code - you don't need to to call it
                    Code:
                              static void force_fpf()
                              {
                                  float x, *y; /* Just declares two variables */
                                  y = &x;      /* Forces linkage of FP formats */
                                  x = *y;      /* Suppress warning message about x */
                              }
                    Thx ur advice works. thx again for sending this article.

                    Comment

                    • rifat
                      New Member
                      • Mar 2007
                      • 2

                      #11
                      Originally posted by vandanasridhar
                      Hi,
                      i m using C++ compiler of versoin 3.0. & this is also giving the same Problem.
                      Will u please tell me how i can use float in structures while using same compiler.
                      vandanasridhar hi
                      I have the problem to.it was simple just use a dumi float variable out of the structure then assign the value and use the variable;

                      struct dum{

                      int a;
                      float f;
                      ----------
                      ---------
                      };

                      int dum_f = f ;

                      Comment

                      • ajeet v
                        New Member
                        • Oct 2011
                        • 1

                        #12
                        float in structures

                        Originally posted by vandanasridhar
                        it is turbo c++.
                        try including <float.h> header file

                        Comment

                        • santhoshlal
                          New Member
                          • Apr 2012
                          • 1

                          #13
                          float values in c structures

                          Originally posted by vandanasridhar
                          Hi,
                          i m using C++ compiler of versoin 3.0. & this is also giving the same Problem.
                          Will u please tell me how i can use float in structures while using same compiler.

                          Hi Vandana
                          Don't worry
                          There is simple solution for ur problem when getting the error
                          "scanf : floating point formats not linked
                          Abnormal program termination"



                          just add the two given lines in ur program

                          extern void _floatconvert() ;
                          #pragma extref _floatconvert


                          and enjoy it



                          one example code is given


                          Code:
                          #include<stdio.h>
                          
                          
                          extern void _floatconvert();
                          #pragma extref _floatconvert
                          
                          
                          
                          struct stud
                          { 	char name[50];
                          	float m1, m2, m3, total;
                          }s[10];
                          void main()
                          {
                          	int n,i;
                          	clrscr();
                          	printf("How many students? \t");
                          	scanf("%d",&n);
                          	for(i=0;i<n;i++)
                          	{
                          		printf("\nGive name of student%d:\t",i+1);
                          		scanf("%s",s[i].name);
                          		printf("\nGive 3  marks of %s\t",s[i].name);
                          		scanf("%f%f%f",&s[i].m1,&s[i].m2,&s[i].m3);
                          		s[i].total = s[i].m1 + s[i].m2 + s[i].m3;
                          	}
                          	printf("\nNAME\t\tMARK1\tMARK2\tMARK3\tTOTAL");
                          	for(i=0;i<n;i++)
                          	{
                          		printf("\n%s\t\t%0.2f\t%0.2f\t%0.2f\t%0.2f",s[i].name, s[i].m1, s[i].m2, s[i].m3, s[i].total);
                          	}
                          }

                          Comment

                          Working...