Skipping over Scanf statement in C

后端 未结 4 1729
别那么骄傲
别那么骄傲 2021-01-29 15:50

I am writing an objective c program for hangman. I need to replicate another program which has been given to me. I have done most of it, but am having an issue. It has to replic

4条回答
  •  一个人的身影
    2021-01-29 16:35

    Use getchar() after scanf() for avoid newline character left in stdin.

    while (i == 0){
    
                printf("\n\n > Please enter a word length: ");
                    scanf("%d", &wordLength);
                    getchar();
                printf("\n\n");
                if (number > 3 && number < 14) {
                    break;
                }
                else printf("number must be between 3 and 14 (inclusive)");
                }
    

提交回复
热议问题