我有這段代碼來檢查第二個日期是否早于第一個日期當我輸入這些沒有逗號 9,9,2021 的順序時程式正常作業但是當我為第一個輸入輸入 09 它跳過第二個輸入并直接跳到第三個輸入我不知道為什么會這樣,因為我對 C 相當陌生
#include <stdio.h>
// Array format [DD,MM,YYYY]
int date[3];
int secondDate[3];
// ANSI color codes
#define RED "\x1b[31m"
#define GREEN "\x1b[32m"
int main()
{
printf("Enter the day of first date: ");
scanf("%i", &date[0]);
printf("Enter the month of first date: ");
scanf("%i", &date[1]);
printf("Enter the year of first date: ");
scanf("%i", &date[2]);
printf("Enter the day of the second date: ");
scanf("%i", &secondDate[0]);
printf("Enter the month of the second date: ");
scanf("%i", &secondDate[1]);
printf("Enter the year of the second date: ");
scanf("%i", &secondDate[2]);
return 0;
}
uj5u.com熱心網友回復:
所述%iformar說明符識別號碼基前綴(即"0x"十六進制,并且'0'為八進制)。該'0'前綴是八進制。And09是無效的八進制,因為八進制數包含數字0-7。
您可以使用說明%d符代替%i,它只解釋十進制數。
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/336484.html
上一篇:如何在C中“多載”scanf?
