Dereferencing Pointer to incomplete type

Asked

Viewed 1,802 times

0

How can I resolve the problem of "Dereferencing Pointer to incomplete type"? I can’t find where the error would be.

The following is the statement:.

typedef struct{
  int dia,mes,ano;
}data;

typedef struct {
  char matricula[10];
  data _matricula;
  data _conclusao;
  char curso[25];
  char universidade[50];

}universitario;

typedef struct {
  data _deposito;
  float renda;  
}poupanca;

typedef struct {

  float salario;
  char orgao_trabalha[50];
  char cargo[12];
  data _contratacao;
}salario;


typedef struct{ 

}corrente;

typedef struct {

  char nome [25];
  char sobrenome[25];
  char endereco[50];
  char email[25];
  char telefone[12];
  char CPF[12];
  int ID; 
  union conta_tipo{
    universitario u;    
    poupanca p;
    salario s;
    corrente c;
  };
}cadastro;


struct cadastro c1;

void preencher_cadastro (struct cadastro *p,int tipo_conta){

  printf ("Insira o nome do cliente a ser cadastrado:  ");
  setbuf (stdin,NULL);
  fgets (p->nome,25,stdin);[![inserir a descrição da imagem aqui][1]][1]
  printf("Insira o sobrenome do cliente a ser cadastrado:  ");
  setbuf (stdin,NULL);
  fgets (p->sobrenome,25,stdin);
  setbuf (stdin,NULL);

According to the IDE, the error is in all fgets.inserir a descrição da imagem aqui

  • A soul descends from purgatory to hell when someone uses Dev-C++...

1 answer

2

When using the type, you are using "struct cadastro", when you should only use "cadastro", since the registration type is already properly defined as struct.

If the struct were defined this way:

struct cadastro { ... membros ... }

Then it would be necessary to use 'struct cadas' for each use of the structure. But the typedef shape is much more usual because it avoids having to repeat the keyword.

In C++ I think the rule is a little different: declaring 'struct cadastre' has the same practical effect as using typedef, and just use the type name (without struct) in the code.

Browser other questions tagged

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