How can I compare a data char from a Struct with 'H' or 'M' to know if the sex entered by keyboard is female or male ..?
How can I compare a data char from a Struct with 'H' or 'M' to know if the sex entered by keyboard is female or male ..?
Suppose you have the struct (for example) defined in the following way:
struct Registro{
char sexo;
};
You can access the sex attribute using the operator ".".
Suppose I need to access the attribute of a single struct
char sexo = miregistro.sexo;
Suppose you have an array of N records of the form array_registers [N], you can enter the sex by doing: '
char sexo = array_registros[i].sexo;
And traverse it with a loop (for - while - do while) as it is more convenient for the developed case.
On how to compare them an easy way is the following:
char sexo = miregistro.sexo;
if(sexo == 'H')
{ //ejecuto alguna tarea
}
else if(sexo == 'M'){
//ejecuto algo
}
I hope you find it useful