我一直对这个代码获得分割故障的演员,我学习C的那一刻..谁能帮助我吗?警告:赋值时将指针整数,未与字符和字符串
错误位置:
char *m;
char *as = concat("helloworld", buf);
*m = sha1(as); <<<<<< as
printf("%s\n", m);
free(as);
concat函数(未矿,用于接合2个字符串):
char* concat(char *s1, char *s2)
{
size_t len1 = strlen(s1);
size_t len2 = strlen(s2);
char *result = malloc(len1+len2+1);//+1 for the zero-terminator
//in real code you would check for errors in malloc here
memcpy(result, s1, len1);
memcpy(result+len1, s2, len2+1);//+1 to copy the null-terminator
return result;
}
的SHA1函数:
char *sha1(char *val){
int msg_length = strlen(val);
int hash_length = gcry_md_get_algo_dlen(GCRY_MD_SHA1);
unsigned char hash[ hash_length ];
char *out = (char *) malloc(sizeof(char) * ((hash_length*2)+1));
char *p = out;
gcry_md_hash_buffer(GCRY_MD_SHA1, hash, val, msg_length);
int i;
for (i = 0; i < hash_length; i++, p += 2) {
snprintf (p, 3, "%02x", hash[i]);
}
return out;
}
由于我问,它们意味着什么用:
//in real code you would check for errors in malloc here
在此先感谢
* M = SHA1(如); m的定义在哪里? –
'字符*米;'就是上面那个,复制失败 – Marco
SHA1正在返回一个char *和M已经是一个char *所以M = SHA1(AS),而不带*请问这个问题有3个问题应做的更好的工作 –