0

Hey i'm pretty new in coding but i wanna know how u can ask the user to type in something more than once.

My code:


#include<stdio.h>

int main() {

// a word

char word [30];
printf("Pls type in any word u want: ");
scanf("%s", word);
printf("\nOkay '%s' is an word!\n\n", word);



// a sign

char sign;
printf("Pls type in any sign u want ");
scanf("%c", &sign);
printf("\nOkay u wanted the sign '%c' to be printed.\n\n", sign);

return 0;

}


but when i run it, im able to type in a word, but cant type in any sign in the next part (program just print


Pls type in any sign u want Okay u wanted the sign ' ' to be printed.

Program ended with exit code: 0


Hope anybody can help me, thank u :)

Marie
  • 11
  • 2
  • The previous scanf call left a new line character in stdin which wasn't discarded. You can remove it by writing a space at the start of the second scanf `scanf(" %c", &sign);`. This tells scanf to munch up that trailing new line and then get on with reading the actual input. Alternatively you could have added a lone `getchar();` call between the scanf expressions. – Lundin Jan 05 '22 at 15:19
  • @Lundin ohh thank u :) – Marie Jan 05 '22 at 16:14

0 Answers0