mardi 1 octobre 2019

Can´t use an union element inside a nested structure as argument for scanf() to store desired value

I have a problem about to use scanf with an union element as an argument which superior union is part of a nested structure.

#include <stdio.h>
int main()
{
    typedef union { float chair; int bed; } HABITATION;
    typedef struct { HABITATION room; int number; } HOUSE;

    scanf("%d",&HOUSE.room.bed);
}

The error message from the compiler is : Error: expected expression before ) >>ROOF<<.

What have i done wrong?

INFO: I currently use C but i am also interested for the same operation and answer in/ for C++.

Aucun commentaire:

Enregistrer un commentaire