Error printing struct member: request for Member in Something not a Structure or Union

Asked

Viewed 511 times

3

I have the following struct:

typedef struct{
    int Numerador ;
    int Denominador ;
} TNumeroRacional ;

In this function I ask the user to insert 2 numerators and denominators to form 2 rational numbers.

void Atribuir (TNumeroRacional* num,TNumeroRacional* num2,int Numerador,int Denominador){
 printf(" a: Atribuir valores para os campos.\n");
 printf("Primeiro numero racional:");
 printf(" Por favor, insira os valores: \n Numerador: ");
 scanf("%d",&num->Numerador);
 printf(" Denominador: ");
 scanf("%d",&num->Denominador);
 printf("Segundo numero racional:");
 printf(" Por favor, insira os valores: \n Numerador: ");
 scanf("%d",&num2->Numerador);
 printf(" Denominador: ");
 scanf("%d",&num2->Denominador);
 printf("Numero racional 1: %d/%d \n",num.Numerador,num.Denominador);
}

When I try to print any element, it appears to me:

error: request for member 'Numerador' in something not a structure or union
error: request for member 'Denominador' in something not a structure or union

I don’t know if my error is in the assignment, but the error message only appears in the printf line.

  • Please enter the entire code of the program, so that it can be more clear your doubt.

1 answer

0


This problem I did not see happen but it may be because the problem is in the call and this was not put in the question, had another error that I fixed in the printf() final:

#include <stdio.h>

typedef struct {
    int Numerador;
    int Denominador;
} TNumeroRacional;

void Atribuir(TNumeroRacional *num, TNumeroRacional *num2, int numerador, int denominador) {
    printf(" a: Atribuir valores para os campos.\n");
    printf("Primeiro numero racional:");
    printf(" Por favor, insira os valores: \n Numerador: ");
    scanf("%d", &num->Numerador);
    printf(" Denominador: ");
    scanf("%d", &num->Denominador);
    printf("Segundo numero racional:");
    printf(" Por favor, insira os valores: \n Numerador: ");
    scanf("%d", &num2->Numerador);
    printf(" Denominador: ");
    scanf("%d", &num2->Denominador);
    printf("Numero racional 1: %d/%d \n", num->Numerador, num->Denominador);
}

int main(void) {
    int numerador = 0, denominador = 0;
    TNumeroRacional num, num2;
    Atribuir(&num, &num2, numerador, denominador);
}

Behold working in the ideone. And in the repl it.. Also put on the Github for future reference.

  • besides in fact I also did not need to have called the numerator and denominator ints, but essentially that was it! thanks.

  • Yeah, I just thought I’d do something with them later.

Browser other questions tagged

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