您可以告诉我 printf 功能中发生了什么问题吗?我一直收到错误
警告:格式'%i'需要类型为'int'的参数,但参数为2 类型'char *'[ - Wformat =] time2.hour,time2.min,time2.sec, time3.hour,time3.min,time3.sec);
然后
警告:格式[-Wformat-extra-args]
的参数太多
有人指出如何解决问题?感谢
#include <stdio.h>
struct time
{
int hour;
int min;
int sec;
};
int main (void)
{
struct time time1, time2, time3;
struct time elapsed_time (struct time time1, struct time time2);
printf("Enter your first time (hh:mm:ss) : ");
scanf ("%i:%i:%i", &time1.hour, &time1.min, &time1.sec);
printf("Enter your second time (hh:mm:ss) : ");
scanf ("%i:%i:%i", &time2.hour, &time2.min, &time2.sec);
time3 = elapsed_time(time1,time2);
printf("The time difference between %.2i:%.2i:%.2i & %.2i:%.2i:%.2i",
"is %.2i:%.2i:%.2i.\n", time1.hour, time1.min, time1.sec,
time2.hour, time2.min, time2.sec, time3.hour, time3.min, time3.sec);
return 0;
}
struct time elapsed_time (struct time time1, struct time time2)
{
struct time time3 = { 0, 0, 0 };
time3.hour = time2.hour - time1.hour;
time3.min = time2.min - time1.min;
time3.sec = time2.sec - time1.sec;
return time3;
}
答案 0 :(得分:1)
看起来你的long printf语句中有两个字符串文字,但printf语句只允许在开头有一个字符串,它必须是包含所有%.2i格式占位符的字符串。
现在,printf获取第一个,然后尝试使用第二个字符串作为第一个字符串的输入参数。
将这两个字符串连接成1个字符串,它应该可以工作。