终端出现奇怪的问题
dcy
posted @ 2009年6月03日 01:48
in 随思杂想
, 1366 阅读
今天无意中发现终端输出出现了很奇怪的问题,一定要在输出中出现\n,要不就会输出数字的时候不输出,输出字符的时候就会出现很奇怪的输出
#include<stdio.h>
int main(void)
{
printf("Hello World!");
return 0;
}
竟然输出这样的东西
dcy@dcy-desktop:~/桌面$ top:~/桌面$
如果是数字的话不会输出打印任何东西,fprintf和fflush(stdout)这些加上都全部没有用
接着再用python测试
#!/usr/bin/env python
import sys
print sys.stdout.write("Hello World!")
一样的问题出现了,只能加入\n,加入\n后又一切正常,一直不明白什么回事,好像以前都不会有这个问题的
因为最近一直用python,用print,会自动帮你换行,今天突然在c发现这个问题,在python测试还是一样,应该是终端的问题,
在gvim里编译运行的话不要\n也正常,就是在终端里不正常,很奇怪
2023年1月27日 02:25
It appears that there is a mysterious issue when running terminal output in C. If the command does not include a "\n" at the end, the output will not appear when the output is a number, and strange diamond rings output will be produced with characters. Even typing "Hello World" fails in this case. To verify the problem, a Python script was tested and the same issue was encountered. Adding "\n" at the end of the command seems to solve the problem, but the source of the issue is still a mystery. It is fortunate that the solution is simple and easy to implement, but it is still a curious phenomenon that requires further investigation.
2023年10月07日 19:03
I ordered this coat from America Jackets and I must say I am amazed with the high quality and fit. You guys can also try it.