Reputation: 11
i've been doing this code and i am new on using pointers. It gives me the error
assignment to 'char *' from incompatible pointer type 'char (*)[10]
and i don't know what can i do to correct it.
The code is as follows:
typedef struct dados_jogo
{
float jogo;
char data[10];
char equipa1[10];
char equipa2[10];
char jog1[50];
char jog2[50];
int mapas1;
int mapas2;
char *venc;
} jogo;
typedef struct equipa
{
char nome[10];
jogador jogadores[NUM];
} team;
Main declarations:
char winner[10];
int op = 1;
int nj = 0, ng = 0;
char nomeficheiro[20];
char ficheiro[20];
jogador players[NUM];
jogo games[JOG];
team eq[EQP];
FILE *fp;
Piece of function where the error is:
if (games[0].mapas1 > games[0].mapas2)
{
games[0].venc = &games[0].equipa1;
strcpy(games[4].equipa1, games[0].venc);
char *ptrw = &games[0].equipa1;
for (i = 0; i < 5; i++)
{
for (j = 0; j < 10; j++)
{
if (strcmp(games[i].jog1, eq[0].jogadores[j].nome) == 0)
{
eq[0].jogadores[j].rating = eq[0].jogadores[j].rating + 0.3;
}
if (strcmp(games[i].jog1, eq[1].jogadores[j].nome) == 0)
{
eq[1].jogadores[j].rating = eq[1].jogadores[j].rating - 0.2;
}
}
}
}
Thanks in advance.
Upvotes: 0
Views: 59
Reputation: 222923
In char *ptrw = &games[0].equipa1;
, games[0].equipa1
is an array of 10 char
, so &games[0].equipa1
is a pointer to an array of 10 char
, which is a different thing from a pointer to a char
. Likely you want char *ptrw = games[0].equipa1;
.
Similarly, games[0].venc = &games[0].equipa1;
should be games[0].venc = games[0].equipa1;
.
Upvotes: 1