c-赋值使指针从整数开始而不进行强制转换

时间:2018-12-04 01:29:34

标签: c

void getFormattedTime(int inputSeconds, int* totalHours, int* totalMinutes, int* totalSeconds) {

   totalHours = (inputSeconds / 3600);
   totalMinutes = (inputSeconds - (3600 * *totalHours)) / 60;
   totalSeconds = (inputSeconds - (*totalHours * 3600) - (*totalMinutes*60));   
   printf("Formatted Total Time: %d:%d:%d", *totalHours, 
   *totalMinutes, *totalSeconds);

}

我不断得到一个赋值,使指针从整数开始而没有强制转换错误,而且我真的不知道如何解决它。请帮忙!

1 个答案:

答案 0 :(得分:0)

您确实是在将整数辅助到指针。试试这个:

*totalHours = (inputSeconds / 3600);
*totalMinutes = (inputSeconds - (3600 * *totalHours)) / 60;
*totalSeconds = (inputSeconds - (*totalHours * 3600) - (*totalMinutes*60));