Closed. This question is off-topic。它当前不接受答案。
                            
                        
                    
                
                            
                                
                
                        
                            
                        
                    
                        
                            想改善这个问题吗? Update the question,因此它是on-topic,用于堆栈溢出。
                        
                        2年前关闭。
                                                                                            
                
        
我正在尝试在程序中接受用户输入,但是一旦用户输入'y'来继续执行一次循环,而循环变得疯狂并最终陷入无限循环,有时甚至不接受scanf输入就退出循环。

char in = 'y';
while(in == 'y'){

  // Code

  printf("do you wanna continue?");
  scanf("%c",&in); //enter y to continue
}

最佳答案

要扫描到char变量,您必须使用%c
像这样


  scanf(“%c”,&in);

10-05 22:37
查看更多