大爱线性表c语言数组,C语言结构体变量指针问题,求助

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

00e27ab806e4881f8254fe7ae8741834.pngHfydkmvos2015.09.25浏览47次分享举报

#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

{

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

{

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

{

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元以上的商品数目结果呢?

*/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值