Yordan Borisov
Yordan Borisov

Reputation: 1652

Stdin problems with structure

struct x_firm
{
    char name[50];
    double lPrice;
    char EIK[14];

    int day;
    int month;
    int year;

};

typedef struct x_firm Firm;

I have problem with filling struct data

printf("Enter firm name:");
scanf("%50s",&firm->name);
printf("Enter firm EIK:");
scanf("%13s",&firm->EIK);
printf("Enter firm last 5 years price:");
scanf("%f",&firm->lPrice);
printf("%f\n",firm->lPrice);
printf("Enter registration date[dd.mm.yyyy]:");
scanf("%2d.%2d.%4d", &firm->day, &firm->month, &firm->year);

The problem is that the lPrice variable isn't initialize and I don't know why! Please help!

Upvotes: 0

Views: 192

Answers (1)

eduffy
eduffy

Reputation: 40224

lPrice is a double, not a float. Use the %lf formatter.

scanf("%lf",&firm->lPrice);

Upvotes: 5

Related Questions