coco1312 2015-09-25 08:02 采纳率: 0%
浏览 1649

C语言结构体变量指针问题,求助

#include
#include
#include
#define N 10
typedef struct
{ char name[10];
double price;
struct { int year;int month;int day ;}date;
}STREC;
int fun(STREC a,double p)
{
int i,j=0;
double q;
for(i=0; i < N ; i++,a++)
{
q=a->price;
if(q>p)
{
*(a+j)=
(a+i);
j++;
}
}
printf("价格在30元以上的商品数目共计:%d",j);
return j;
}

main()
{ STREC s;
s=(STREC *)malloc(10*sizeof(STREC));
int i,j;double p;
printf("\n请输入10种商品的数据包括品名、单价和出厂日期: ");
for(i=0; i < N; i++,s++)
{
scanf("%s %lf %d %d %d",s->name,&s->price,&s->date.year,&s->date.month,&s->date.day);
printf("%s %lf %d-%d-%d",s->name,s->price,s->date.year,s->date.month,s->date.day);
}
p=30.0;
j=fun(s,p);
printf("价格在30元以上的商品数目共计:%d",j);
for(i=0; i < j; i++)
{

printf("%s %lf %d-%d-%d",s->name,s->price,s->date.year,s->date.month,s->date.day);
}
printf("\n");
}
/

1.程序运行结果为:

请输入10种商品的数据包括品名、单价和出厂日期:
book 30.09 1930 9 30
fruit 99 2015 9 30
apples 9.9 2015 9 25
milk 56 2015 9 25
meat 19.8 2015 9 25
book 30.09 1930 9 30
fruit 99 2015 9 30
apples 9.9 2015 9 25
meat 19.8 2015 9 25
apples 9.9 2015 9 25
价格在30元以上的商品数目共计:0价格在30元以上的商品数目
共计:0====为何没有统计价格在30元以上的商品数目结果呢?
*/

  • 写回答

2条回答 默认 最新

  • Robot-C 2015-09-25 08:05
    关注

    typedef struct treeT
    {
        ElemType key;
        struct treeT* left;
        struct treeT* right;
    }treeT, *pTreeT;

    int main(int argc, char argv[]) {
        pTreeT root = NULL;
        pTreeT
    a ;......
    答案就在这里:c语言 结构体 指针变量
    ----------------------你好,人类,我是来自CSDN星球的问答机器人小C,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。

    评论

报告相同问题?

悬赏问题

  • ¥15 fpga自动售货机数码管(相关搜索:数字时钟)
  • ¥15 用前端向数据库插入数据,通过debug发现数据能走到后端,但是放行之后就会提示错误
  • ¥15 python天天向上类似问题,但没有清零
  • ¥30 3天&7天&&15天&销量如何统计同一行
  • ¥30 帮我写一段可以读取LD2450数据并计算距离的Arduino代码
  • ¥15 C#调用python代码(python带有库)
  • ¥15 飞机曲面部件如机翼,壁板等具体的孔位模型
  • ¥15 vs2019中数据导出问题
  • ¥20 云服务Linux系统TCP-MSS值修改?
  • ¥20 关于#单片机#的问题:项目:使用模拟iic与ov2640通讯环境:F407问题:读取的ID号总是0xff,自己调了调发现在读从机数据时,SDA线上并未有信号变化(语言-c语言)