0
Guys, I made this program to receive name, address and phone of 2 people, he receives the data of the first people quietly, problems begin with the data of the second person, the name and address of the second person he receives, but the program simply skips the entrance of the phone field and goes to the next step, which is to print the information on the screen, the printing for the data of the first registration happens normally, but for the second person, it prints only the name followed by a number in place of the address that is always equal in all tests (32767), after that the program finishes, wanted to understand why this happens, I have checked the code several times and did not find the error.
#include <stdio.h>
#include <string.h>
struct Pessoas
{
char nome[30];
char endereco[50];
int telefone;
};
int main ()
{
int i;
void print ();
void recebe ();
struct Pessoas pessoas[2];
for (i=0; i!=2; i++)
{
recebe(&pessoas[i]);
}
printf ("\n\n");
for (i=0; i!=2; i++)
{
print (&pessoas[i]);
}
return 0;
}
void recebe (struct Pessoas *y)
{
fflush (stdin);
fgets (y->nome, 30, stdin);
fgets (y->endereco, 50, stdin);
scanf ("%d", &y->telefone);
}
void print (struct Pessoas *x)
{
printf ("%s", x->nome);
printf ("%s", x->endereco);
printf ("%d", x->telefone);
}
only one detail, the command
for
I think it would look better this way:for (i=0; i<2; i++)
, pq you are starting at zero and incrementing 1 in 1– Ricardo Pontual