我的代码是这个printf()的呈现奇怪的结果
#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()的呈现奇异数。你能解释一下为什么会发生这种情况?
此外,当你说,它提出了“奇怪的结果”,你这是什么意思呢? – qaphla
不知道实际输出是什么,不,我们不能。 – DiMono
你使用什么编译器?它不是给出“格式太少的参数”警告或类似的吗? –