linux - warning: format %s expects type char * but argument 2 has type int
阿神
阿神 2017-04-17 11:36:18
0
1
1296

尝试用crypt的时候遇到了这个问题
源代码如下:

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv)
{
printf("%s\n", crypt(argv[1], argv[2]));
return 0;
}

用命令gcc -o test lizi.c -lcrypt编译连接时有如下警告:
lizi.c:7:2: 警告: 格式 ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘int’ [-Wformat]

没理由啊,crypt的返回值不可能是整数啊,而且如果运行则会提示段错误

阿神
阿神

闭关修行中......

reply all(1)
大家讲道理
#include <crypt.h>
 /*或者*/
#define _GNU_SOURCE
#include <unistd.h>

Please see: man feature_test_macros

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!