我已成功安装了NetBeans for C,但我不知道出什么问题了,因为每当我编写任何代码时,它都会说“ build success”,但不会执行。当我按下运行按钮时,什么都没有发生,Netbeans只是编译代码,但屏幕上什么都没有显示。
以下是简单的代码:
int main(void) {
int a=0;
printf("input any number");
scanf("%d",&a);
return (EXIT_SUCCESS);
}
这是它的编译:
""/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk QMAKE= SUBPROJECTS= .build-conf
make.exe[1]: Entering directory `/c/Users/timekeeper/Documents/NetBeansProjects/ft'
"/C/MinGW/msys/1.0/bin/make.exe" -f nbproject/Makefile-Debug.mk dist/Debug/MinGW-Windows/ft.exe
make.exe[2]: Entering directory `/c/Users/timekeeper/Documents/NetBeansProjects/ft'
mkdir -p build/Debug/MinGW-Windows
rm -f "build/Debug/MinGW-Windows/main.o.d"
gcc -std=c99 -c -g -MMD -MP -MF "build/Debug/MinGW-Windows/main.o.d" -o build/Debug/MinGW-Windows/main.o main.c
mkdir -p dist/Debug/MinGW-Windows
gcc -std=c99 -o dist/Debug/MinGW-Windows/ft build/Debug/MinGW-Windows/main.o
make.exe[2]: Leaving directory `/c/Users/timekeeper/Documents/NetBeansProjects/ft'
make.exe[1]: Leaving directory `/c/Users/timekeeper/Documents/NetBeansProjects/ft'
BUILD SUCCESSFUL (total time: 34s)
""
我该怎么办?提前致谢
该stdout
流是行缓冲。这意味着在遇到换行符()之前,您fwrite
或其他人不会实际将其写入您的终端。printf
stdout
\n
因此,您的程序缓冲了字符串,并在上将其阻塞,以scanf
等待您的输入stdin
。一旦发生这种情况,您的控制台窗口就会关闭,并且您永远不会看到打印内容。
要解决此问题,请在字符串末尾添加换行符:
printf("input any number:\n"); // Newline at end of string
或手动导致stdout
被冲洗:
printf("input any number: ");
fflush(stdout); // Force stdout to be flushed to the console
此外,我假设该(total time: 34s)
数字包括程序等待您键入内容的时间。您非常耐心,大约34秒后,终于将键盘上的东西捣碎了,然后程序结束,控制台窗口关闭了。
或者,如果Netbeans没有打开单独的控制台窗口,则这全部发生在Netbeans IDE的那些MDI窗格中。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句