GNU GCC doesn't load float point support in struct, f21

asked 2015-01-17 15:28:37 -0600

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I can print f but not the other double values in struct.

// Planetary database using structures
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct 
{
    char name[15];
    double dist_miles;
    int moons;
}planet;
void main()
{
    planet p[8];
    int i;
    double f=9.87654;
    printf("%f",f);
    printf("Enter data for planet 3 : \n");
    printf("Enter the name : ");
    scanf("%s",&p[2].name);
    printf("Enter the distance from Sun in millions of miles : ");
    scanf("%f",&p[2].dist_miles);
    printf("Enter the number of moons known : ");
    scanf("%d",&p[2].moons);
    printf("Enter data for planet 2 : \n");
    printf("Enter the name : ");
    scanf("%s",&p[1].name);
    printf("Enter the distance from Sun in millions of miles : ");
    scanf("%f",&p[1].dist_miles);
    printf("Enter the number of moons known : ");
    scanf("%d",&p[1].moons);
    for(i=1;i<3;i++)
    {
        printf("\nThe data for planet %s : \n",p[i].name);
        printf("The distance from Sun in millions of miles is %lf \n",p[i].dist_miles);
        printf("The number of moons known are %d \n",p[i].moons);
    }
}
</string.h></stdlib.h></stdio.h>
edit retag flag offensive close merge delete

Comments

Compile with compiler option -Wall and you will see the problem for yourself... (BTW: It has nothing to do with structs)

Axel Sommerfeldt gravatar imageAxel Sommerfeldt ( 2015-01-17 16:26:20 -0600 )edit

Exactly, -Wall did the thing. Also %f is not accepted by gcc. We should use %lf for double.

SantoshHoropter gravatar imageSantoshHoropter ( 2015-01-27 05:54:34 -0600 )edit