2009-08-11 40 views

回答

9

最有可能的,stdout是行缓冲。您的程序不会调用fflush或发送换行符,以便缓冲区不会被写出。

#include <stdio.h> 

int main(void) { 
    printf("hai\n"); 
    for(;;) 
    ; 
    return 0; 
} 

也看到C FAQquestion 12.4What's the correct declaration of main()?

+0

为什么downvote?未能从不返回的函数中包含“return 0”? – 2009-08-11 13:14:53

+0

你甚至没有修复他的包括错字... – 2009-08-11 13:21:03

+0

我downvoted因为你有什么不编译。 – 2009-08-11 13:22:39

3

默认情况下,标准输出趋于行缓冲,因此您没有看到任何内容的原因是因为您没有刷新行。

这将工作:

#include <stdio.h> 
int main (int argC, char *argV[]) 
{ 
    printf("hai\n"); 
    for(;;) 
     ; 
    return 0; 
} 

或者,你可以fflush标准输出或使程序退出刚刚摆脱无限循环:

#include <stdio.h> 
int main (int argC, char *argV[]) 
{ 
    printf("hai"); 
    return 0; 
} 

,但你可能想换行反正有。

2

您的(;;)循环停止从被刷新流。正如其他人所建议的那样,在正在输出的字符串中添加一个换行符,或者明确地刷新流:

fflush(stdout); 

printf后。并纠正#include的拼写。

相关问题