#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元以上的商品数目结果呢?
*/
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,以上是依据我对问题的理解给出的答案,如果解决了你的问题,望采纳。
main里s加了10次,调用fun之前你要减回去啊,没报错已经是奇迹了
还有你s究竟是什么类型?