马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#define _CRT_SECURE_NO_WARNINGS
#define NUM 3
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
typedef struct Computer
{
char brand[20];
double price;
char color[20];
}TEAC;
void printComputer(TEAC* t,int i)
{
printf("电脑的品牌为:%s\n", t[i].brand);
printf("电脑的价格为:%f\n", t[i].price);
printf("电脑的颜色为:%s\n", t[i].color);
}
void getMaxPrice(TEAC* t) //问题:这里形参为啥要用一级指针,用元素TEAC t不行吗?
{
if (t[0].price > t[1].price)
{
if (t[0].price > t[2].price)
{
printComputer(t, 0);
}
else //t[0].price < t[2].price
{
printComputer(t, 2);
}
}
else //t[0].price < t[1].price
{
if (t[1].price > t[2].price)
{
printComputer(t, 1);
}
else //t[0].price < t[1].price
{
printComputer(t, 2);
}
}
}
void main()
{
int i;
TEAC t1 = { "华为",2000.5,"红色" };
TEAC t2, t3;
strcpy(t2.brand, "联想");
t2.price = 5000.0;
strcpy(t2.color, "紫色");
strcpy(t3.brand, "西门子");
t3.price = 4000.5;
strcpy(t3.color, "蓝色");
TEAC t[NUM] = { t1,t2,t3 };
for (i = 0; i < NUM; ++i)
{
printComputer(&t, i);
}
printf("==============\n");
getMaxPrice(&t);
system("pause");
}
|