作者OppOops (Oops)
看板b99902HW
标题[讨论] 有人试过crypt() function吗
时间Wed Sep 21 11:54:14 2011
我在系上linux尝试
test.c
~
1 #include <stdio.h>
2 #include <unistd.h>
3
4 int main(int argc,char** argv){
5
6 if(argc!=3) exit(0);
7 else
8 printf("%s\n",crypt(argv[1],argv[2]));
9 return 0;
10 }
>>
gcc test.c -lcrypt
>>
./a.out apple am
却会出现Segmentation fault
(我看manual page,crypt应该是:
char *crypt(const char *key, const char *salt);
实际上得到的return vale 却是int...Orz)
我做错了甚麽..
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.4.192
1F:推 LoganChien:#define _XOPEN_SOURCE 09/21 12:31
2F:推 ianlini:你怎麽知道return value是int? 09/21 16:00
3F:推 marrvosal:楼上 我猜 compile 时说不是能把 int assign 给 char 09/21 16:39
我改成 char* temp = crypt("apple","am");
并在前面#define _XOPEN_SOURCE
我还是得到 warning: initialization makes pointer from integer without a cast
[enabled by default]
※ 编辑: OppOops 来自: 140.112.4.192 (09/22 15:05)
4F:→ OppOops:google一下一楼的 我还是重新再看看缺甚麽@@" 09/22 15:08
5F:推 LoganChien:放在第一行。所有 include 之前 09/23 14:44
6F:→ OppOops:楼上一语道破 ~"~ 感谢 09/23 17:47