"[Error] expected Expression before 'creature'" in function

Asked

Viewed 326 times

1

The board is a "creature" of my struct:

typedef struct{
    int status;
    char classe;
    int saude;
    int def;
    int atc;
    char elixir;
}criatura;

No . h:

void exibe(criatura tabuleiro[5][10]); // exibe o tabuleiro

The call no . c with the functions:

criatura tabuleiro[5][10]; // declarei aqui
// entraram alguns códigos aqui
exibe(criatura tabuleiro); // chamei a função aqui

The function:

void exibe(criatura tabuleiro[5][10]){
    int i,j;

    for(i=0;i<10;i++){
        if(i==0){
            printf("     1");
        }
        if(i==1){
            printf("   2");
        } ............................. (apenas um tabuleiro)

But for some reason I get the mistake:

In function 'tabuleiro':
[Error] expected expression before 'criatura'
C:\Users\...\dfv2\Makefile.win  recipe for target 'funcoes.o' failed

If anyone knows what’s going wrong, I’ll thank you! A hug!

1 answer

1


The function call is wrong.

You did:

exibe(criatura tabuleiro);

Should have done:

exibe(tabuleiro);

C already knows it is a creature. In this case, you confused the compiler by passing a type and a name to it. And this structure is not valid when calling a function. In this case, the grammar C asks for a call to consist of:

  1. Function name
  2. Parenthesis
  3. Values interspersed with commas
  4. Close parenthesis

It has some variations (C accepts function pointers), but in general this is it.

It is also worth saying that for the header it is necessary to know the type criatura before declaring the function.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.