|

楼主 |
发表于 2020-3-11 19:43:58
|
显示全部楼层
#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)
{
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");
}
上面代码出了点错 下面贴新的代码 是因为数组名t是指针 所以才用一级指针来接的吗?
如果不修改指针的内容,比如打印数据 直接用一级指针?
如果修改指针的指向 就用二级指针? |
|