3
Can anyone tell me what I’m doing wrong? I need to store the data of 3 people on struct and then print.
This error is appearing:
request for Member ːname' in Something not a Structure or Union|
request for Member ːidade' in Something not a Structure or Union|
request for Member ːpeso' in Something not a Structure or Union|
request for Member ːaltura' in Something not a Structure or Union|
request for Member ːvetor' in Something not a Structure or Union|
But I don’t understand what’s wrong yet.
#include <stdio.h>
#include <stdlib.h>
int main() {
struct pessoas {
char nome[20];
int idade;
float peso;
float altura;
};
struct pessoas usuario[3];
int i;
for (i=0; i<=2; i++)
{
printf("\n");
printf("\nDigite seu nome: ");
gets(usuario.nome);
printf("\nDigite sua idade: ");
scanf("%i", &usuario.idade);
fflush(stdin);
printf("\nDigite seu peso: ");
scanf("%f", &usuario.peso);
fflush(stdin);
printf("\nDigite sua altura: ");
scanf("%f", &usuario.altura);
fflush(stdin);
}
for (i=0; i<=2; i++)
{
printf("\n%s, com %i anos voce pesa %.2f e tem %.2f de altura!", usuario.vetor[i], usuario[i].idade, usuario[i].peso, usuario[i].altura);
}
printf("\n\n");
return(0);
}
From now on, thank you. ;)
usuario
is an array: it has elements. It’s not a struct, it has no members. I suppose you want anything likeusuario[0].nome
. Oh! Never use itgets()
. It is impossible to use safely and there is an alternative function that you can safely use:fgets()
– pmg
Ah, ok. I’ll start using fgets() so thank you. ;)
– Marcielli Oliveira