Jump to content

Problema com o Scanf


jpedro7

Recommended Posts

Quando tento carregar um elemento de uma tabela bidimensional a partir do keyboard acontece o seguinte:

se digitar duas palavras o scanf parte-me em duas linhas porquê?

Código:

int i;
char texto[80];

printf("Inserir o Texto \n");
scanf("%s", &texto_l[tot_ln][0],80);
for (i=1;i<=25;i++)
{
	printf("Inserir linhas \n");
	scanf("%s", &texto_l[tot_ln][i],80);
	if (strcmp(texto_l[tot_ln][i], "end") == 0)
	{
		break;
	}
}
tot_ln++;

Quando é executado a instrução printf("Inserir linhas \n"); eu escrevo "Primeira Linha" a seguir o scanf("%s", &texto_l[tot_ln][i ],80); escreve-me duas ocurrências no vector.

A 1ª ocurrência com o valor "Primeira" e segunda com "Linha".

Só deveria ser um elemento com "Primeira Linha" .

Alguem pode ajudar ?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.