Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/71.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
C编程,getch()在IDE Netbean中不工作?_C_Netbeans_Getch - Fatal编程技术网

C编程,getch()在IDE Netbean中不工作?

C编程,getch()在IDE Netbean中不工作?,c,netbeans,getch,C,Netbeans,Getch,我的C实验室项目必须在Windows7上的Netbeans中运行,使用主文件C。 要求输入任何键以继续 在DevC中,我可以使用getch()来解决这个问题,但在Netbeans中,它向erorr显示函数是标识符。 我的问题是: 1.我可以使用哪个函数来处理此案例? 2.我应该使用Get来执行此操作吗?没有这样的标准函数getch。可能您需要getchar或getc如果您的c实验室在linux操作系统上,那么此代码可能会有所帮助 #include <stdlib.h> #includ

我的C实验室项目必须在Windows7上的Netbeans中运行,使用主文件C。 要求输入任何键以继续

在DevC中,我可以使用
getch()
来解决这个问题,但在Netbeans中,它向erorr显示函数是标识符。 我的问题是: 1.我可以使用哪个函数来处理此案例?
2.我应该使用Get来执行此操作吗?

没有这样的标准函数
getch
。可能您需要
getchar
getc

如果您的c实验室在linux操作系统上,那么此代码可能会有所帮助

#include <stdlib.h>
#include <stdio.h>

#include <termios.h>


/*
    warning:
    error handling was ommited for clarity.
    check [tcgetattr, tcsetattr ] documentation

*/


int getch(){

    int                 ret;
    struct termios      back;
    struct termios      tmp;
    int fd =            0;      //stdin

    tcgetattr(fd, &back);       // a backup
    tcgetattr(fd, &tmp);

    // code get from man page
    tmp.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP
                   | INLCR | IGNCR | ICRNL | IXON);
    tmp.c_oflag &= ~OPOST;
    tmp.c_lflag &= ~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);

    tmp.c_cflag &= ~(CSIZE | PARENB);
    tmp.c_cflag |= CS8;
    // endof man page

    // apply configuration
    tcsetattr(fd, TCSANOW, &tmp);

    ret=getchar();

    // reset back the configuration
    tcsetattr(fd, TCSANOW, &back);

    return ret;
}



int main(){

   int ret;
    printf("Press a key:");
    ret=ret= getch();
    printf("%c\n",ret);
    printf("DONE\n");
}
#包括
#包括
#包括
/*
警告:
为清晰起见,建议进行错误处理。
检查[tcgetattr,tcsetattr]文档
*/
int getch(){
int ret;
结构termios背面;
结构termios tmp;
int fd=0;//stdin
tcgetattr(fd,&back);//备份
tcgetattr(fd和tmp);
//从手册页获取代码
tmp.c|U iflag&=~(IGNBRK | BRKINT | PARMRK | ISTRIP)
|INLCR | IGNCR | ICRNL | IXON);
tmp.c_of lag&=~OPOST;
tmp.c|lflag&=~(ECHO | ECHONL | ICANON | ISIG | IEXTEN);
tmp.c|cflag&=~(CSIZE | PARENB);
tmp.c|u cflag |=CS8;
//结束手册页
//应用配置
tcsetattr(fd、TCSANOW和tmp);
ret=getchar();
//重置配置
tcsetattr(fd、TCSANOW和back);
返回ret;
}
int main(){
int ret;
printf(“按一个键:”);
ret=ret=getch();
printf(“%c\n”,ret);
printf(“完成”\n);
}

如下面的链接所示,正确的函数是
getchar
。 如果您使用的是GCC(与netbeans一起),那么它就是
getc

正如我所看到的,两者都是线程安全和阻塞的


@Haris,但这需要用户按回车键key@VuVAnh是否需要输入任何键才能继续,或者Haris解决方案是否也可以?另外,在什么操作系统上使用netbeans?窗户?Linux@我用的是windows7。Haris的解决方案并不像我最近尝试的那样有效。要求是“程序应该要求用户输入任何要重复的键…”@VuVAnh,所以getch应该这样做。您已经可以尝试使用getch(新MS名称)而不是getch(旧DOS名称),但如果仍然无法解决此问题,请发布一段很短的完整代码,表明它不起作用,并发布完整的错误消息:UI显示“按任意键继续”。然后等待。我必须输入任何键来做进一步的功能,但输入的键不允许在UI中显示。