0

I'm new to coding, I'm portuguese, so my English is not so good.

My question:

int main()
{
    typedef struct Coiso{
        char cor_cabelo[100];
        int idade;
        float altura;

    }Coiso;


    printf ( "Insira a cor do cabelo do coiso\n");
    scanf ( "%s", Coiso);

    printf ( "%s\n", Coiso.cor_de_cabelo);

return 0;
}

So, I compiled this in geany and get an error: expected expression before "coiso".

Why do I get this error?

Alex Yu
  • 3,412
  • 1
  • 25
  • 38

1 Answers1

1

As others have said Coiso is just a custom type, like int or bool. You have to declare a variable with it. So to edit your code.

Coiso var;

scanf ( "%s", var);

printf ( "%s\n", var.cor_de_cabelo);
JBatstone
  • 167
  • 7
  • 3
    `scanf ( "%s", var);` is not correct, it should be `scanf ( "%s", var.cor_de_cabelo);` – Osiris Jan 08 '19 at 20:56
  • Osiris, i understand the idea. it's perfect. now it's work – Carlos Mota Jan 08 '19 at 20:59
  • `typedef struct X {...}X; struct {...}X; typedef struct {...} X; struct X X; ...` This could be really confusing when you learn C. I recommend you read this post : https://stackoverflow.com/questions/1675351/typedef-struct-vs-struct-definitions. The explanations are realised in a very didactic manner. – Stef1611 Jan 08 '19 at 21:02