>  Q&A  >  본문

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

阿神阿神2715일 전1299

모든 응답(1)나는 대답할 것이다

  • 大家讲道理

    大家讲道理2017-04-17 11:38:18

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

    Please see: man feature_test_macros

    회신하다
    0
  • 취소회신하다