Error in passing a structure by reference C

-2

In this exercise it is necessary to change only the characters a through b, ie printf output should be like this {B, 1.5, 2.7} {A, 3.9, 4.2}

typedef struct{char n;float x;float y;}Ponto;
void troca_nomes(Ponto *a, Ponto *b){
    char aux;
    aux = *a.n;
    *a.n = *b.n;
    *b.n = aux; 
}
int main(void){
    Ponto a = {'A', 1.5, 2.7};
    Ponto b = {'B', 3.9, 4.2};
    troca_nomes(&a,&b);
    printf("{%c,%.1f,%.1f}\n",a.n,a.x,a.y);
    printf("{%c,%.1f,%.1f}\n",b.n,b.x,b.y);
}
    
asked by anonymous 11.11.2018 / 21:43

1 answer

1

*a.n is wrong. With this you are trying to access the position value of the n pointer inside the a structure. But n is not a pointer, a is the pointer.

It would have to be (*a).n or a->n

    
11.11.2018 / 22:08