我无法找到解决方法,这是关于学习字符计数的(我正在使用Kernighan-Ritchie版)。我的问题栏显示:
“警告:格式指定类型为'int',但参数的类型为'long'[-Wformat] printf(“%1d \ n”,nc); ~~~ ^〜%1ld“
这是代码:
#include <stdio.h>
int main()
{
long nc;
nc = 0;
while (getchar() != EOF)
++nc;
printf("%1d\n", nc);
}
我在Mac上使用Qt Creator 3.1.1。 Xcode 6.2(6C131e)上存在相同问题。
有帮助吗?预先感谢。
long
的正确格式说明符是%ld
,而不是%d
。 %d
需要一个int
。
替换
printf("%1d\n", nc);
与
printf("%ld\n", nc);
解决问题。