一个简单的c语言问题
test.c文件如下#include<stdio.h>#include<errno.h>
int main(void)
{
fprintf(stderr,"EACCES:%s\n",strerror(EACCES));
return 0;
}
编译加-W选项生成警告信息
gcc -W test.c -o test
结果有这样的警告信息:
test.c:6:2: 警告: 格式 ‘%s’ expects argument of type ‘char *’, but argument 3 has type ‘int’ [-Wformat]
但是strerror的返回值在man中显示是char *
为啥警告提示是int
我用的ubuntu12.04系统
求大神解答我的疑惑 #include <string.h>
char * strerror(int num)所以strerror()返回的是char *
回复 2# zsszss0000
thank you:mrgreen:
确实是这样的
但为什么没用#include<string.h>还是可以运行了
还有就是你为啥一眼就看出问题来了啊
man strerror
to make sure what .h file is needed
and then include it in your .c file回复 3# lxy572535121
页:
[1]