I'm a beginner in C programming and I'm trying to write a code to send the input from one terminal to another terminal in wich I'm running a program (I don't know if it makes any difference but it's a telnet program). The reason for this is that often I'm writing a command to the program and it sends some text, making what I wrote so far impossible to change. My intention was running a program in a small terminal under the main one, and send the commands through this one, I've looked at many questions at stack overflow to write this program but it doesn't seem to work, so I decided to ask here what am I doing wrong? Sorry if that's not an apropriate question for this site, but it is the best I know. Here is my code:
(I'd also appreciate any sugestions you might have)
#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;
}