读书人

printf函数的一点有关问题

发布时间: 2012-03-12 12:45:32 作者: rapoo

printf函数的一点问题
这个代码为什么会输出mor呢,这个输出格式不是一般用在浮点数的吗?
[code=C/C++][/code]
char *g="morning";
printf("%.3s",g);

[解决办法]
printf HELP [.prec]How Output Precision Is Affected
.nn characters or n decimal places are printed.
If the output value has more than n characters, the output might be truncated or rounded. (Whether this happens depends on the type character.)
printf本身应有的功能,只是用的较少而已

读书人网 >C语言

热点推荐