printf("Please enter the start date of your trip Month/Day/Year seperated by a space:");
scanf("%d %d %d", &month, &day, &year);
checkC = error_date(month,day,year);
if (checkC == 2)
{
travel_month[i][0] == month;
travel_day[i][0] == day;
travel_year[i][0] == year;
}
else
while (checkC==1)
{
printf("Please enter the start date of your trip Month/Day/Year seperated by a space:");
scanf("%d %d %d", &month, &day, &year);
checkC= error_date(month,day,year);
}
for (row = 0; row < trip_num; row++)
{
for (col=0; col < DEST; col++)
printf("Trip#:%d %d/%d/%d\n", row+1, travel_month[row][col], travel_day[row][col], travel_year[row][col]);
}
return 0;
}
int error_date(int month, int day, int year)
{
int checkC;
if ( ((month > 0) && (month <= 12)) && ((day > 0) && (day <= 31)) && ((year> 2000) && (year < 2050)) )
{
checkC = 2;
return checkC;
}
else
{
printf("Invalid date please re-enter date\n");
checkC = 1;
return checkC;
}
}
我是否错误地加载了月/日/年,当我打印出数组时,我不断得到奇怪的整数。
答案 0 :(得分:3)
您需要使用单个等号进行分配:
travel_month[i][0] == month;
travel_day[i][0] == day;
travel_year[i][0] == year;
应该是
travel_month[i][0] = month;
travel_day[i][0] = day;
travel_year[i][0] = year;