Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用curses中的initscr()时在错误位置打印_C_Linux_Shell_Ncurses - Fatal编程技术网

使用curses中的initscr()时在错误位置打印

使用curses中的initscr()时在错误位置打印,c,linux,shell,ncurses,C,Linux,Shell,Ncurses,我有以下代码 initscr(); while ((ch = getch()) != '#') { system("ls"); } endwin(); 问题是结果通常不会打印出来。 这就是它给我结果的方式: project project.c shell.c test test1.c test2.c Project shell Signal Labs test1 test2 text.txt 但是我希望结果是这样的: 我的意思是我希望

我有以下代码

initscr();
while ((ch = getch()) != '#')
{
    system("ls");
}
endwin();
问题是结果通常不会打印出来。 这就是它给我结果的方式:

project  project.c  shell.c  test   test1.c  test2.c
        Project  shell      Signal Labs  test1  test2    text.txt
但是我希望结果是这样的:
我的意思是我希望它的格式如下:

project  project.c  shell.c      test   test1.c  test2.c
Project  shell      Signal Labs  test1  test2    text.txt

我确信有一个缺少的函数或与
initscr()

相关的东西,'system'调用写入标准输出,而curses库写入相同的文件描述符,但它们的输出可能不会以相同的方式进行缓冲,curses库还设置了输出终端模式,以改变回车和换行的工作方式。所以你真的不想以那种方式将两者合并

您可以从命令中读取结果,并使用诅咒打印该结果。类似的内容(请参见手册页面的部分):


如果使用
系统
,则无法控制输出,您执行的命令将处理所有输出。如果要使用curses库编写输出,则必须自己打印输出。在这种情况下,我不明白你为什么使用诅咒。你有没有试过不用它?你的要求有点不清楚。您没有提供足够的代码供我们分析。
initsrc
是否打印?@Someprogrammerdude我使用诅咒,因为我想处理这样一个想法:当用户单击向上箭头时,它会加载最后键入的注释,但这是一段简短的代码,只是为了知道如何解决这个问题。@PaulOgilvie我希望输出的格式正常。我所说的“正常方式”是指与终端相同的形状。然而,通过使用诅咒,输出就像问题中提到的那样。我希望你能理解。initsrc()打开一个新窗口。
initscr();
cbreak();
noecho();
while ((ch = getch()) != '#')
{
    FILE *pp = popen("ls", "r");
    if (pp != 0) {
        while ((ch = fgetc(pp)) != EOF) {
            addch(ch & 0xff);
        }
        pclose(pp);
    }
}
endwin();