【发布时间】:2013-09-10 19:55:32
【问题描述】:
我的代码是这样的
#include<stdio.h>
int main(void)
{
unsigned short height = 0;
unsigned short width = 0;
const unsigned short MIN_SIZE = 3;
printf("Enter the values for the width and the height minimum of %u\n:",
MIN_SIZE);
scanf(" %hd %hd", &width, &height);
if (width < MIN_SIZE)
{
printf("The value of width %u is too small. I set this to %u \n",
width, MIN_SIZE);
width = MIN_SIZE;
}
if (height < MIN_SIZE)
{
printf
("The value of height %u is too small. I setting this to %u \n"),
height, MIN_SIZE;
height = MIN_SIZE;
}
for (unsigned int i = 0; i < width; ++i)
{
printf("*");
}
return 0;
}
例如,当我给出宽度为 7 且高度为 0 时,printf() 会显示奇怪的数字。你能解释一下为什么会这样吗?
【问题讨论】:
-
另外,当你说它呈现“奇怪的结果”时,你的意思是什么?
-
不知道实际输出是什么,不,我们不能。
-
你使用什么编译器?它不会给出“格式参数太少”警告或类似警告吗?