我的代碼是這個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
你使用什麼編譯器?它不是給出「格式太少的參數」警告或類似的嗎? –