我从以下c代码收到此错误。
if (system("clear") == -1)
{
fprintf(stderr, "system() failed");
}
不要使用system()
。如果您的程序的调用者可以操作命令的搜索路径,那么可以执行任何名为Clear的命令而不是您想要的命令。改为在C中实现该功能:
#include <stdio.h>
void clear() {
// Move cursor to top-left corner and clear the erase entire screen
fputs("\e[;1H\e[2J", stdout);
}