我是 C 编程的初学者,我正在尝试编写代码以将输入从一个终端发送到另一个终端,我正在运行一个程序(我不知道它是否有任何区别,但它是一个 telnet程序)。这样做的原因是我经常给程序写一个命令,它会发送一些文本,使我到目前为止写的内容无法更改。我的意图是在主终端下的一个小终端中运行一个程序,并通过这个发送命令,我在堆栈溢出中查看了很多问题来编写这个程序,但它似乎不起作用,所以我决定在这里问我做错了什么?抱歉,如果这不是本网站的适当问题,但这是我所知道的最好的。这是我的代码:
(我也很感激你可能有任何建议)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char command[1001];
char px[1001 + 8 + 13 + 3] = "";
char p1[8] = "echo | ";
char p2[13] = " > /dev/pts/";
char p3[3] = "";
int term, compLimit, i;
compLimit = 14;
printf("Put terminal number here: ");
scanf("%d", &term);
sprintf(p3, "%s%d", p3, term);
while(strncmp(px, "exit mudclient", compLimit))
{
for(i = 0; i < 1021; i++) px[i] = 0;
scanf("%s", command);
strcat(px, p1);
strcat(px, command);
strcat(px, p2);
strcat(px, p3);
system(px);
}
return 0;
}