"[Error] request for Member in Something not a Structure or Union"

Asked

Viewed 369 times

-1

Guys, I’m trying to make a struct that receives information from the user and then it displays the information. But you are showing this error when I compile '[Error] request for Member in Something not a Structure or Union".

Follows the Code...

#include <stdio.h>
#include <stdlib.h>

struct funcionario
{
    char nome[40];
    char cargo[40];
    int cpf[11];
};

cad_func[2];


int main(void) {

    int i;

    printf("INSIRA SEUS DADOS.\n\n\n");

    for(i=0; i<2; i++)
    {
        printf("nome: ");
        fflush(stdin);
        gets(cad_func[i].nome);

        printf("cargo: ");
        fflush(stdin);
        gets(cad_func[i].cargo);

        printf("cpf: ");
        scanf("%d", &cad_func[i].cpf);


    }

    printf("Dados dos funcionarios:\n\n");

    for(i=0; i<2; i++){
        printf("Nome: %s", cad_func[i].nome);
        printf("Cargo: %s", cad_func[i].cargo);
        printf("Nome: %d", cad_func[i].cpf);

    }
    return 0;
}

Thank you!!!

1 answer

0


This error is occurring because you did not inform the type of the variable cad_func[2].

To fix this, just inform the guy, which is the struct funcionario:

struct funcionario cad_func[2];

With this your program already starts to compile and run.

Browser other questions tagged

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