0
I looked in several places about it but I couldn’t find any correct answer, I wanted to know the correct method of filling a structure vector passed by reference to one function and then printing in another, in this code below I tried to do something of the kind to try to fill but it did not work, thanks since.
#include <stdio.h>
struct carnaval
{
char nome [10];
char cor [10];
int quantidade;
};
int main ()
{
int x=1;
struct carnaval blocos[2];
void listar();
void incluir();
void buscar();
while (x!=0)
{
printf ("1) Incluir\n");
printf ("2) Listar\n");
printf ("3) Buscar\n");
printf ("0) Sair\n");
scanf ("%d", &x);
if (x==0)
{
break;
}
switch (x)
{
case 1:
incluir (blocos);
break;
case 2:
listar (blocos);
break;
case 3:
buscar ();
break;
case 0:
break;
default:
printf ("valor inválido\n");
break;
}
}
}
void incluir (struct carnaval *incluido[])
{
int i;
for (i=0; i<2; i++)
{
getchar();
fgets ((*incluido)[i].nome, 10, stdin);
fgets ((*incluido)[i].cor, 10, stdin);
scanf ("%d", &(*incluido)[i].quantidade);
}
}
void listar (struct carnaval print[])
{
int y;
for (y=0; y<2; y++)
{
printf ("\n%s", print[y].nome);
printf ("%s", print[y].cor);
printf ("%d\n\n", print[y].quantidade);
}
}
void buscar ()
{
printf ("teste\n");
}
It really worked, thank you very much for the answer and for the help!
– Marlon Vinícius Buosi
@Marlonviníciusbuosi if my answer helped solve your problem, you should accept it to signal to the community that your problem has been solved. More details, cf: https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-reply.
– user142154