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

发布于 2022-08-28 01:00:29 字数 438 浏览 11 评论 0

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如果没有 2022-09-04 01:00:29
#include <crypt.h>
 /*或者*/
#define _GNU_SOURCE
#include <unistd.h>

Please see: man feature_test_macros

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文