0

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.

6
  • 1
    Which line does the error refer to? Commented Jun 30, 2021 at 20:02
  • 1
    The compiler prints a line number with the error message (and likely a column number too) or the IDE you are using shows you which line of code causes the error. When asking questions about compiler messages, always include that information in your post. Commented Jun 30, 2021 at 20:04
  • line "games[0].venc = &games[0].equipa1;" Commented Jun 30, 2021 at 20:08
  • i did, the error is on the top of the question. Commented Jun 30, 2021 at 20:09
  • @DuochannelYT: The error message is there, but the line number is not. (Of course, since you only provided some of the lines, we would not have the line number. In the future, you should provide a minimal reproducible example and/or indicate which line causes the error.) Commented Jun 30, 2021 at 20:13

1 Answer 1

1

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;.

Sign up to request clarification or add additional context in comments.

4 Comments

You missed a &. The expression &games[0].equipa1 is a pointer to an array of 10 char. The expression games[0].equipa1 would (in most contexts) return a pointer to the first char in the array games[0].equipa1
@HAL9000: Thanks, fixed.
So i took out most of the "&" but i still have some errors in other lines.
there is a line where i have this "ptrw = games[0].equipa1;". How would i do it to have the pointer "ptrw" to point to the value of "games[0].equipa1"?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.