这是我在 stackoverflow 上的第一篇文章,我希望我没有违反任何规则或重新发布。我一直在寻找我的警告的答案。虽然我可以找到一些类似的实例,但我无法得到有效的修复。我希望能得到一些帮助。
我需要找到与 hashfunction(myname) 的哈希冲突。所以我做了一些研究并将这个递归函数放在一起,它将测试每个可能的字符串到指定的长度并在找到字符串时打印它。看一看。
void findCollision(char prefix[], int max_length);
int main() {
printf("Finding collison\n");
char blank[0] = {'a'};
findCollision(blank,999);
printf("Press Enter to Continue");
while( getchar() != '\n' );
return 0;
}
void findCollision(char prefix[], int max_length){
char c;
char temp[sizeof(prefix)+1];
for(c = 'a'; c <= 'z'; c++){
strcpy(temp, prefix);
strcat(temp, c);
if(hashFunction(temp) == -408228925 && temp != 'myname'){
printf("found it! --->");
printf("%s", temp);
}
}
for(c = 'a'; c <= 'z'; c++){
strcpy(temp, prefix);
strcat(temp, c);
if(sizeof(prefix) < max_length){
findCollision(temp, max_length);
}
}
}
当使用哈希码编译时(如果需要,我也可以提供)我得到这些错误。
----------Build Started--------
----------Building project:[ hash - Debug ]----------
/home/mustbelucky/hash/hash.c
22:2: warning: excess elements in array initializer [enabled by default]
22:2: warning: (near initialization for ‘blank’) [enabled by default]
34:3: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [enabled by default]
/usr/include/string.h
136:14: note: expected ‘const char * __restrict__’ but argument is of type ‘char’
/home/mustbelucky/hash/hash.c
35:50: warning: character constant too long for its type [enabled by default]
35:47: warning: comparison between pointer and integer [enabled by default]
42:3: warning: passing argument 2 of ‘strcat’ makes pointer from integer without a cast [enabled by default]
/usr/include/string.h
136:14: note: expected ‘const char * __restrict__’ but argument is of type ‘char’
----------Build Ended----------
我已经用谷歌搜索了它们,但没有成功找到成功的修复程序。有什么想法吗?这个项目将在 2 天内到期,我感觉它必须运行一段时间。