我正在尝试学习 C,但我已经遇到了问题。我认为它微不足道,但我需要知道它。我已经写了:
char *seconds_to_string (guint seconds)
{
long days, hours, minutes;
char *time = NULL;
const char *minutefmt;
const char *hourfmt;
const char *secondfmt;
days = seconds / (60 * 60 * 24);
hours = (seconds / (60 * 60));
minutes = (seconds / 60) - ((days * 24 * 60) + (hours * 60));
seconds = seconds % 60;
minutefmt = ngettext ("%ld minute", "%ld minutes", minutes);
hourfmt = ngettext ("%ld hour", "%ld hours", hours);
secondfmt = ngettext ("%ld second", "%ld seconds", seconds);
minutefmt = ngettext ("%ld minute", "%ld minutes", minutes);
hourfmt = ngettext ("%ld hour", "%ld hours", hours);
secondfmt = ngettext ("%ld second", "%ld seconds", seconds);
char *fmt;
/* Translators: the format is "X hours X minutes X seconds" */
fmt = g_strdup_printf (_("%s %s %s"), hourfmt, minutefmt, secondfmt);
time = g_strdup_printf (fmt, hours, minutes, seconds);
g_free (fmt);
---------------------------------------------------------------------
return time;
}
警告符合:
time = g_strdup_printf (fmt, hours, minutes, seconds);
有人可以帮忙吗?
更新:
编译
scan-build make CFLAGS='-Wformat-nonliteral'