I want to make my program ask to enter a phrase and then a letter, but although the phrase asks for it, the letter no longer asks for it, although it DOES show the text "Letter: ", which is followed by the command line of the console...
The code is this:
char frase[100];
char letra;
printf("Frase: ");
scanf("%s", frase);
printf("Letra: ");
scanf("%c", &letra);
Besides, I think that if my sentence contains more than one word then it doesn't consider it...
Thank you!
With
In
frase
will be stored all the characters that are written until:Because of this last condition, '%s' is not able to read complete lines. For this task you have
getline
:Although you can also try to program it on your own:
Or, checking that it does not exceed 100 characters: