scanf不在结构中存储适当的信息

问题描述

| 我
scanf
有问题。
scanf
没有在结构中存储适当的信息。代码的一部分是:
if( figure->pro.p_category == \'C\' || figure->pro.p_category == \'c\' ){
    printf(\"Enter data line> \");
    result += scanf(\"%s %d%c %d %d %d%c\",(figure->pro.name),&temp,\\
    &figure->pro.money,&figure->exp.month,&figure->exp.year,\\
    &figure->ais.aisle_num,&figure->ais.aisle_side);
    if ( figure->pro.money == \'C\')
        figure->pro.cents = temp;
    else if( figure->pro.money == \'D\')
        figure->pro.dollars = temp;
}
figure->pro.name
figure->exp.month
存储不同的值。 我的结构是:
typedef struct {
    char name[20];
    char p_category,sub_p_category,money;
    int cents,dollars;
}product_t;

typedef struct {
    int aisle_num;
    char aisle_side;
}aisle_t;

typedef struct {
    int day,month,year;
}experiment_t;

typedef struct {
    int day,year;
}packaging_t;

typedef union {
    product_t pro;
    experiment_t exp;
    packaging_t pack;
    aisle_t ais;
}figure_t;
例如;
input> corn 89C 11 2010 11B
来自输出功能的这段代码:
printf(\"The %s costs %d cents,expires in \",my_figure.pro.name,my_figure.pro.cents);

            print_exp_month(my_figure);
            printf(\"of %d,and is displayed in %d%c\",my_figure.exp.year,my_figure.ais.aisle_num,\\
            my_figure.ais.aisle_side);
其输出:   的      费用89美元,于2000年到期,并显示在12B中 正确的输出:   玉米价格为89美分,于2000年11月到期,并显示在12B中     

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)