I'm making a simple program about sorting five teams from 1st to 5th.. but i wanted to make it by using Array of pointers & passing structures methods. here is what i've done..
#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;
}
when i compile it i get this error:
warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘struct league **’ [-Wformat=]
printf("%s\n", &Ptable[i]);
what is the right way to code this without making too many changes on my code? because i want to be using array of pointers with structures in a code like this.
Ptable[i]is a pointer to a struct league. Each league struct has 5 members each of which are 20 character arrays. The five Ptable[i}->teami statements don't do anything.