替换system直接写入
#include <stdlib.h> #include <stdio.h> int main() { char user_input[100]; printf("请输入一个字符串: "); fgets(user_input, sizeof(user_input), stdin); // 去除换行符 user_input[strcspn(user_input, "\n")] = 0; char command[200]; sprintf(command, "echo \"%s\"", user_input); system(command); return 0; }