3
Good afternoon,
Currently studying Language C and I come across a situation that has locked in the progress of studies,I made a structure that receives registration and address. The compiler does not accuse errors, but when the wheel behaves strangely not allowing to receive all the data, the expected output on each line should be:
Name->
Age->
Street->
Number->
Where each line points to the data to be filled after typing and giving enter. The error occurs after informing age:
Name-> Jeferson
Age-> 35
Rua-> Numero->
In the same line of Street-> soon after appears Number->,tried to put the " n" but it also jumps straight to Number->.
Follow the code, and I appreciate any help offered.
#include<stdio.h>
#include<stdlib.h>
struct endereco{
char rua[50];
int numero;
};
struct cadastro{
char nome[50];
int idade;
struct endereco ender;
};
int main(int argc, char const *argv[])
{
struct cadastro c;
//Lê do teclado uma string e armazena no campo nome
printf("Nome-> ");
gets(c.nome);
//Lê do teclado um valor inteiro e armazena no campo idade
printf("Idade-> ");
scanf("%d",&c.idade);
//Lê do teclado uma string
//e armazena no campo rua da variavel ender
printf("Rua-> \n ");
gets(c.ender.rua);
//Lê do teclado um valor inteiro
//e armazena no campo numero da variavel ender
printf("Numero-> ");
scanf("%d",&c.ender.numero);
system("pause");
return 0;
}
Your mistake is the line break free output?
– Samuel Ives
Is because of the
gets
, q ñ purge stdin the break character d line– Marcelo Shiniti Uchimura
I also tried fgets(), the same thing happened...
– Jeferson Silva
Try to use
getline
– Marcelo Shiniti Uchimura