我正在尝试实现一个简单的C程序来自学指针。每当我运行它时,我都会得c warning: assignment makes pointer from integer without a cast [enabled by default]
。我对这个问题有所了解,但我是C的初学者,我不知道如何解决它。请协助。
#include <stdio.h>
#include <math.h>
void print_time(long input, int *hours, int *minutes, int * seconds);
int main() {
//char message[30];
//int message_size;
int hours, minutes, seconds;
long input;
printf("Enter the number of seconds: ");
scanf("%ld",&input);
print_time(input, &hours, &minutes, &seconds);
printf("The equivalent is: %d hour(s), %d minute(s), %d second(s).", hours,minutes,seconds);
return 0;
}
void print_time(long input, int *hours, int *minutes, int * seconds){
hours = (int)floor(input/3600);
minutes = (int)floor((input%3600)/60);
seconds = (int)input - (hours*3600)-(minutes*60);
}
答案 0 :(得分:0)
试试这个......
void print_time(long input, int *hours, int *minutes, int * seconds){
*hours = (int)floor(input/3600);
*minutes = (int)floor((input%3600)/60);
*seconds = (int)input - (hours*3600)-(minutes*60);
}
你将指针传递给整数并将它们视为整数。