0
The program is not reading mine fgets()
getting there he jumps.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
float altura, peso,pesoidealm,pesoidealf;
char sexo[10];
printf("Digite sua altura\n");
scanf("%f",&altura);
printf("Digite seu peso\n");
scanf("%f",&peso);
printf("Digite seu sexo\n");
fgets(sexo,9,stdin);
pesoidealm=(72.7*altura)-58;
pesoidealf=(62.1*altura)-44.7;
if(!(strcmp(sexo,"masculino")))
{
printf("Peso Ideal:%f\n",pesoidealm);
}
system("PAUSE");
return 0;
}
And do you need to type in all the sex? Can’t it just be the initial like everyone else does? And it needs to be with
fgets()
?– Maniero
It is that this asking in the exercise. And how to use gets (can give bufferoverflow), so I think the best to use is fgets().
– José Augusto Valim
And why not
scanf()
even?– Maniero
I think it’s because it’s a string.
– José Augusto Valim