小编nit*_*h.s的帖子

如何通过从键盘获取任何值来打破Linux上的C循环?

我正在构建的程序在无限循环中运行,其中包含一个开关盒.我想在每种情况下插入一个while循环并在循环中执行一些操作,但是一旦给出键盘输入,循环就应该退出.因此,在从键盘获取输入之后,另一个案例在其中嵌套了while循环,并且该过程继续.

结构是:

while()//infinite loop
    {
    ...............      //operations
    ...............      //operations
    switch()
        {
        case 1:
        ...............    //operations
        ...............    //operations
        while()//infinite loop
             {
             ..............
             ..............
             exit if there is any input from keyboard
             }
        break;

        case 2:
        ...............    //operations
        ...............    //operations
        while()//infinite loop
             {
             ..............
             ..............
             exit if there is any input from keyboard
             }
        break;


        case n:
        ...............    //operations
        ...............    //operations
        while()//infinite loop
             {
             ..............
             ..............
             exit if there is any input from keyboard
             }
        break;
        }
  }
Run Code Online (Sandbox Code Playgroud)

有什么办法吗???

c linux while-loop

5
推荐指数
2
解决办法
2723
查看次数

标签 统计

c ×1

linux ×1

while-loop ×1