gpt4 book ai didi

C Segmentation Fault,多个警告

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:31 25 4
gpt4 key购买 nike

<分区>

这是我在 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 天内到期,我觉得它必须运行一段时间。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com