我正在制作一个关于从第1到第5排序五个团队的简单程序..但是我想通过使用传递结构方法的指针&指向它。这里是我做了什么..传递指向结构的指针的数组
#include <stdio.h>
#include <string.h>
struct league
{
char team1[20];
char team2[20];
char team3[20];
char team4[20];
char team5[20];
};
char *Arrange(struct league *table)
{
struct league *Ptable[5] = {0};
int i;
Ptable[0]-> team5;
Ptable[1]-> team2;
Ptable[2]-> team3;
Ptable[3]-> team1;
Ptable[4]-> team4;
for (i = 0; i < 5; i++)
printf("%s\n", &Ptable[i]);
return Ptable[i];
}
int main()
{
struct league table;
strcpy(table.team1,"Arsenal");
strcpy(table.team2,"Man City");
strcpy(table.team3,"LiverPool");
strcpy(table.team4,"Totenham");
strcpy(table.team5,"Chelsea");
printf("League table:\n");
Arrange(&table);
return 0;
}
当我编译它,我得到这个错误:
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘struct league **’ [-Wformat=]
printf("%s\n", &Ptable[i]);
有什么不对我的代码进行太多的修改实现代码的正确方法?因为我想在这样的代码中使用结构体的指针数组。
此代码不会执行您认为的操作。 'Ptable [i]'是一个结构联盟的指针。每个联盟结构有5个成员,每个成员是20个字符数组。五个Ptable [i} - > teami声明不做任何事情。 – bruceg
请注意,这是托特纳姆热刺(热刺) - 中间有两个t。和利物浦;没有资本在中间。 –