【问题标题】:Stdin problems with structure结构的标准输入问题
【发布时间】:2011-05-21 16:00:32
【问题描述】:
struct x_firm
{
    char name[50];
    double lPrice;
    char EIK[14];

    int day;
    int month;
    int year;

};

typedef struct x_firm Firm;

我在填充结构数据时遇到问题

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);

问题是 lPrice 变量没有初始化,我不知道为什么! 请帮忙!

【问题讨论】:

  • 你的结构声明是什么样的?

标签: c struct scanf


【解决方案1】:

lPricedouble,而不是 float。使用%lf 格式化程序。

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

【讨论】:

    猜你喜欢
    • 2017-09-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多