首页 > warning: format %s expects type char * but argument 2 has type int

warning: format %s expects type char * but argument 2 has type int

尝试用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的返回值不可能是整数啊,而且如果运行则会提示段错误


#include <crypt.h>
 /*或者*/
#define _GNU_SOURCE
#include <unistd.h>

Please see: man feature_test_macros

【热门文章】
【热门文章】