Help: Valuing a char array of a struct within an if

1

I'm trying to set the value of a char vector of a struct inside an if, but without success ...

A struct itself:

    struct ficha {
        char nome[31], classificacao[31], telefone[21];
        float altura, peso, imc;
    }paciente1, paciente2, aux;

Following are the attempts:

Temptation 1:

    if (paciente1.imc<18.5) {
        paciente1.classificacao = {"Abaixo do peso", 31};
    } else if ...

Attempt 2:

    if (paciente1.imc<18.5) {
        paciente1.classificacao = "Abaixo do peso";
    } else if ...

Try 3:

    if (paciente1.imc<18.5) {
        paciente1.classificacao = ("Abaixo do peso", [31]);
    } else if ...

Thanks in advance for the help!

    
asked by anonymous 15.07.2014 / 23:36

1 answer

1

If I'm not mistaken, it's not possible to set the contents of an array directly, so you have to set the contents of your positions. The strcpy function can help you:

if (paciente1.imc<18.5) {
    strcpy(paciente1.classificacao, "Abaixo do peso");
} else if ...
    
15.07.2014 / 23:42