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

编程 crypto Linux c linux编程

园艺师之剪 11 years, 3 months ago

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

Please see: man feature_test_macros

丶Shana answered 11 years, 3 months ago

Your Answer