[英]crypt() function in C not working
The following is my file named crack.c: 以下是我的名为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;
}
}
The following is what I type into the command line: 以下是我在命令行中键入的内容:
jharvard@appliance (~/Dropbox/hacker2): clang -o crack -lcrypt crack.c
The following is what the command line spits back out at me: 以下是命令行向我吐出的内容:
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.
Anyone know what's going on? 有人知道发生了什么吗?
I had the same problem, and I realized that changing the header 我遇到了同样的问题,我意识到更改标题
#define _XOPEN_SOURCE
#include <unistd.h>
by 通过
#define _GNU_SOURCE
#include <crypt.h>
makes disapear the error in compilation time 使编译时的错误消失
Make sure you have the define and include for crypt as the very first lines at the top of your file before any other includes. 确保在文件顶部的最前面几行具有crypt的define和include,然后再包含其他。
#define _XOPEN_SOURCE
#include <unistd.h>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.