问题描述
我正在尝试用 C 编写日历系统,但我经常收到同样的错误:
main.c:26:49: warning: format specifies type 'char *' but the argument has type
'char (*)[10]' [-Wformat]
我的代码是
char months[12][10] = {
"January","February","march","April","May","June","July","August","September","October","November","December"
};
用于声明“月”,以及
int i;
for(i = 0; i < 12; i++)
{
printf("string = %s \t address = %u\n",months + i,(unsigned int)months + i);
}
用于打印。我曾尝试用 *months
、**months
和 (*char)months
替换月份,但都没有奏效。我在这里检查了多个问题,但其中一个涉及我没有使用的 scanf
。即便如此,我还是尝试了对我不起作用的答案。另一个涉及函数,答案是将 **
附加到参数的开头。这对我也不起作用。我知道我的问题可能很简单,但是,我无法找到解决方案。如有任何帮助,我将不胜感激。
解决方法
试试:
printf("string = %s \t address = %u\n",months[i],(unsigned int)&months[i]);
您必须更改 %u
才能消除另一个警告。