I don't think you need to spawn a new shell to display the line. If what you want is like the comment box, give this a try ( N.B: I have not implemented any escape character, so backspace and escape won't work)
Had a little help from here What is Equivalent to getch() & getche() in Linux?
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAXLEN 255
#ifdef _WIN32
#include <conio.h>
#else
#include <termios.h>
static struct termios old, newT;
/* Initialize new terminal i/o settings */
void initTermios(int echo)
{
tcgetattr(0, &old); /* grab old terminal i/o settings */
newT = old; /* make new settings same as old settings */
newT.c_lflag &= ~ICANON; /* disable buffered i/o */
newT.c_lflag &= echo ? ECHO : ~ECHO; /* set echo mode */
tcsetattr(0, TCSANOW, &newT); /* use these new terminal i/o settings now */
}
/* Restore old terminal i/o settings */
void resetTermios(void)
{
tcsetattr(0, TCSANOW, &old);
}
/* Read 1 character - echo defines echo mode */
char getch(int echo)
{
char ch;
initTermios(echo);
ch = getchar();
resetTermios();
return ch;
}
#endif // _WIN32
int main()
{
char arrayInput[MAXLEN + 1];
static char printArray[MAXLEN + 15];
static char tmp[5];
char c;
int i,len=0;
printf("Begin\n");
for(i=0;i<MAXLEN;i++)
{
putchar('\r');
c = getch();
for(len=0;len<MAXLEN;len++)
putchar(' ');
putchar('\r');
arrayInput[i]=c;
arrayInput[i+1] = '\0';
strcpy(printArray,"");
strcpy(printArray,arrayInput);
strcat(printArray," Size is:: ");
sprintf(tmp,"%d",i+1);
strcat(printArray,tmp);
printf("%s",printArray);
}
return 0;
}