Problem with struct: "Expected expression before"

0

The following problem

  

expected expression before 'eqp'

in the line of the function 'data' where the value is read and I could not identify the reason for it.

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

typedef struct equipamento{
int codigoequipamento;
int tempoativo;
float potencia;
float consumonomes;
char equipamento[30];
}eqp;
typedef struct equipamento eqp;

void menu(void);
void dados(void);
int main(){

   setlocale(LC_ALL, "Portuguese"); 
   int resp=0;
   do{
       menu();
       scanf ("%d",&resp);
       if(resp == 1){ // Para caso deseje-se cadastrar
        dados();

       }if(resp == 2){// Caso deseje-se consultar oq já foi cadastrado

       }if(resp == 3){
          break;
       }if((resp > 3) || (resp < 1)){
          printf("Valor invalido\n");
       }
       }while (resp != 3);
       return 0;
 }
void menu(void){  //menu
  printf("---------------------------------------\n");
  printf("| Sessão de cadastro de equipamentos  |\n");
  printf("---------------------------------------\n");
  printf("Digite 1 para cadastrar\n");
  printf("Digite 2 para consultar os cadastros\n");
  printf("Digite 3 para sair\n");
}

void dados(void){ // Função para ler dados

  printf("Entre com o codigo do equipamento: ");
  scanf("%d",&eqp.codigoequipamento);
}
    
asked by anonymous 19.09.2018 / 20:13

1 answer

0

There are a lot of errors there and I tried to fix the main ones (I kept some things that I would do differently in real cases), keeping a different organization and nomenclature, removing what is redundant and unnecessary and switching to what is most appropriate. p>

The error in focus is that you are trying to manipulate the type and not a variable. You have to create the variable. I imagine I wanted to create in the main code and pass as parameter to use in the function that will manipulate it, so that's what I did.

I suggest paying attention to every detail of what I've changed (even blanks), it's usually not the case, it's all thought out.

#include <stdio.h>
#include <locale.h>

typedef struct {
    int codigo;
    int tempoativo;
    float potencia;
    float consumonomes;
    char nome[31];
} Equipamento;

void menu(void) {
    printf("---------------------------------------\n");
    printf("| Sessão de cadastro de equipamentos  |\n");
    printf("---------------------------------------\n");
    printf("Digite 1 para cadastrar\n");
    printf("Digite 2 para consultar os cadastros\n");
    printf("Digite 3 para sair\n");
}

void dados(Equipamento *equipamento) {
    printf("Entre com o codigo do equipamento: ");
    scanf("%d", &equipamento->codigo);
}

int main() {
   setlocale(LC_ALL, "Portuguese"); 
   int resp = 0;
   Equipamento equipamento;
   do {
       menu();
       scanf("%d", &resp);
       switch (resp) {
       case 1:
           dados(&equipamento);
           break;
       case 2:
           break;
       }
       if (resp > 3 || resp < 1) printf("Valor invalido\n");
    } while (resp != 3);
}

See running on ideone . And no Coding Ground . Also put it in GitHub for future reference .

    
19.09.2018 / 20:24