C如何使用esc从while循环退出

时间:2019-03-12 15:29:37

标签: c string loops concurrency break

我想在控制台中输入“ esc”键后退出。但是不幸的是我不知道如何在不重写整个程序的情况下执行此操作。此刻在ctrl + D之后退出循环。

    char* getUserInput(int bytes)
    {
      char* buffer = malloc(bytes);
      char* line = malloc(bytes);
      size_t len = 0;


      while (getline(&line, &len, stdin) > 0)  //I'd like to add one while condition
    //here, that will check if esc was pressed, like &&(_getch()!=27) 
    //or &&(!strcmp(line, (char)27)

      {
        strcat(buffer, line);
        line = malloc(bytes);
      }

      buffer[strlen(buffer) - 1] = '\0';
      return buffer;
    }

0 个答案:

没有答案