-2
I’m trying to make a simple program to start messing with C.
#include <stdio.h>
#include <stdlib.h>
#include <locale.h>
int main(void)
{
char nome[100];
char dataNascimento[10];
char telefone[11];
char endereco[200];
char email[100];
char nomeAnimal[100];
char especie[100];
char raca[100];
setlocale(LC_ALL, "Portuguese");
printf("Nome: \n");
scanf(" %s", &nome);
printf("Data de Nascimento: \n");
scanf(" %s", &dataNascimento);
printf("Endereço: \n");
scanf(" %s", &endereco);
printf("E-mail: \n");
scanf(" %s", &email);
printf("Telefone: \n");
scanf(" %s", &telefone);
printf("Nome Animal: \n");
scanf(" %s", &nomeAnimal);
printf("Espécie: \n");
scanf(" %s", &especie);
printf("Raça: \n");
scanf(" %s", &raca);
printf("Cliente Cadastrado Com Sucesso!");
return 0;
}
When I enter a word in the name line, the program works:
But when I insert two words, the scanf between Date of Birth and Address does not work:
An observation that was not commented on in the answers is about the
&
. It is not necessary in thescanf
when the goal is to read astring / vetor
, because the vector variable already points to the address, that is, if we havevetor[10]
thenvetor == &vetor[0]
.– Júlio Evêncio