[英]crypt() function in C not working
以下是我的名为crack.c的文件:
#include <stdio.h>
#define _XOPEN_SOURCE
#include <unistd.h>
void execute(char *alpha)
{
char *beta = crypt(alpha);
printf("%s", beta);
}
int main(int argc, string argv[]){
....
execute(argv[1]);
else{
printf("You submitted %d command line arguments. That's an issue. You need to submit exactly one.", argc);
return 1;
}
}
以下是我在命令行中键入的内容:
jharvard@appliance (~/Dropbox/hacker2): clang -o crack -lcrypt crack.c
以下是命令行向我吐出的内容:
crack.c:8:19: warning: implicit declaration of function 'crypt' is
invalid in
C99 [-Wimplicit-function-declaration]
string beta = crypt(alpha);
^ crack.c:8:12: warning: incompatible integer to pointer conversion initializing
'string' (aka 'char *') with an expression of type 'int'
[-Wint-conversion]
string beta = crypt(alpha);
^ ~~~~~~~~~~~~ 2 warnings generated.
有人知道发生了什么吗?
我遇到了同样的问题,我意识到更改标题
#define _XOPEN_SOURCE
#include <unistd.h>
通过
#define _GNU_SOURCE
#include <crypt.h>
使编译时的错误消失
crypt
的功能签名为:
char * crypt (const char *key, const char *salt)
看来您忘记了一个参数! 所以你的线:
string beta = crypt(alpha);
应该是这样的:
string beta = crypt(alpha, salt);
确保在文件顶部的最前面几行具有crypt的define和include,然后再包含其他。
#define _XOPEN_SOURCE
#include <unistd.h>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.