gpt4 book ai didi

c - 数组加载问题

转载 作者:太空宇宙 更新时间:2023-11-04 07:40:07 25 4
gpt4 key购买 nike

  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;
}
}

我是否加载了错误的月/日/年,当我打印出数组时,我总是得到奇怪的整数。

最佳答案

您需要使用单个等号进行赋值:

      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;

关于c - 数组加载问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5112534/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com