I'm using Ncurses in C to create an input and output window. When the user types in something, I want to use mvwprintw()
to display the string to the output window. I stored the return value of wgetch()
in an array, how do I convert the int array to char pointer
/* cmd is an array already have the int value for the character,
I declare it like char cmd[100], and store the int value return by wgetch() into
it*/
char realcmd[100];
for (int i = 0; i < 100; i ) {
if (cmd[i] == 0){
realcmd[i] = '\0';
}
else{
realcmd[i] = cmd[i] 0;
}
}
This is how I convert the int array to char pointer, but I only get the first character. For example, if I type in " hello world"
, I only get 'h'
.
CodePudding user response:
How do you call the function mvwprintw()
?
Which format string to you use as fourth argument? It seems to me, that you use the char (%c
) conversion qualifier instead of the string (%s
) qualifier.
Try this:
mvwprintw(win, 0, 0, "%s", realcmd);
mvwprintw()
use the same conversion qualifier as printf()
. You can read this in the man page from mvwprintw()
.