处理开关盒后,C不';t读取system()函数

处理开关盒后,C不';t读取system()函数,c,switch-statement,pyautogui,C,Switch Statement,Pyautogui,初学者警觉 我在C中尝试使用3个函数和system()函数。它还包括一个用pyautogui模拟(alt+tab)的Python文件。问题是 在完成开关语句后,它以某种方式传递系统(“清除”)命令 以下是C代码: #include <stdio.h> #include <stdlib.h> int makeSwitch() { int x; printf("\nType and enter one of them:"); printf

初学者警觉

我在
C
中尝试使用3个函数和
system()
函数。它还包括一个用pyautogui模拟(alt+tab)的
Python
文件。问题是 在完成
开关
语句后,它以某种方式传递
系统(“清除”)
命令

以下是
C
代码:

#include <stdio.h>

#include <stdlib.h>

int makeSwitch() {

  int x;
  printf("\nType and enter one of them:");
  printf("\n\n(1) - (2)");
  printf("\n\n> ");
  scanf("%d", & x);

  int y;
  switch (x) {

  case 1:
    printf("I like 1");
    y = 1;
    break;
  case 2:
    y = 2;
    printf("I like 2");
    break;

  default:
    system("python3 tb.py");
    y = 3;
    break;
  }

  system("clear");

  return y;
}
void makePrint(int b) {
  system("clear");

  if (b == 1) {
    printf("I like one\n");
  } else if (b == 2) {
    printf("I like two\n");
  } else if (b == 3) {
    printf("Hotkey: alt + tab\n");
  } else {
    printf("Command not found\n");
  }

}
int main() {

  int x = makeSwitch();
  makePrint(x);

  return 0;
}
产出(1):

产出(2):

输出(y!=1 | | y!=2):

所以在
默认设置之后:
系统(“清除”)工作!我想知道为什么

我的猜测是,我必须刷新一些保留空间并阻止
system()
函数运行的东西


感谢阅读。

忽略
scanf()的返回值将自担风险。它将允许您验证您是否成功地在中读取了某些内容。否则,您可能会使用旧的甚至非初始化的值。要使其可见,请引入另一个案例4,并将init
x
引入到4。与其他案例不同,据我所知,您的默认案例不会将任何内容打印到stdout。如果是这样的话,我想你会发现这个输出在屏幕上的配置和持久性与另外两个案例打印的输出是一样的。如果这个输出确实在屏幕上持续,那么我同意有些奇怪的事情似乎正在发生,但我不准备接受它与
switch
语句有任何关系。
pyautogui.hotkey("alt","tab")
I like 1I like one
I like 2I like two
Hotkey: alt + tab