0
Good morning! I’m learning C and I had a question about using strings, I wanted to know if there is difference to use this form:
char palavra[255];
printf("Digite uma palavra: ");
setbuf(stdin, 0); //limpar o buffer
fgets(palavra, 255, stdin); // ler a string
palavra[strlen(palavra)-1] = '\0';
printf("%s", palavra);
to use in this way:
printf("Digite uma palavra: ");
scanf("%s", palavra);
printf("%s\n", palavra);
From now on I thank you all!
Ah understood, but in practice I could use anyone who wouldn’t make an impact?
– Arthur mgbr
The second would have a certain impact, but only if you have one
scanf
subsequent and you do not enter the space bar.– Marcelo Shiniti Uchimura
I get it, thank you!
– Arthur mgbr