gpt4 book ai didi

c - 编译C代码时出现错误C2113

转载 作者:行者123 更新时间:2023-11-30 19:41:40 25 4
gpt4 key购买 nike

我对 C 没有任何经验(尽管我经常使用 C#),但我希望编译一些 C 代码:

http://practicalcryptography.com/cryptanalysis/stochastic-searching/cryptanalysis-bifid-cipher/

当我使用 VS2015 中的开发人员命令提示符用 cl.exe 编译它时,出现错误:

c:\simple>cl bifidcrack.c
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.23026 for x86
Copyright (C) Microsoft Corporation. All rights reserved.

bifidcrack.c
bifidcrack.c(113): error C2113: '-': pointer can only be subtracted from another
pointer
bifidcrack.c(114): error C2113: '-': pointer can only be subtracted from another
pointer

c:\simple>

为什么编译失败?其他人(在页面评论中)据说已经编译它没有任何问题。

C:\简单包含:

C:\simple>dir
Volume in drive C is OS
Volume Serial Number is AA86-3F24

Directory of C:\simple

22/10/2015 02:50 <DIR> .
22/10/2015 02:50 <DIR> ..
12/10/2015 12:06 4,491 bifidcrack.c
12/10/2015 12:06 7,301,392 qgr.h
12/10/2015 12:06 574 scoreText.c
12/10/2015 12:06 44 scoreText.h
4 File(s) 7,306,501 bytes
2 Dir(s) 14,560,649,216 bytes free

C:\simple>

根据要求,以下是有问题的行:

char *bifidDecipher(char *key, int period, char *text, char *result, int len){
int i, j;
char a,b; /* the digram we are looking at */
int a_ind,b_ind;
int a_row,b_row;
int a_col,b_col;

for (i = 0; i < len; i += period){
if (i + period > len){
period = len - i;
}
for (j = 0; j < period; j ++){
a = text[i+(j/2)];
b = text[i+((period+j)/2)];

/*if (index(key,a) == NULL || index(key,b) == NULL) break;*/
113 a_ind = (int)(index(key,a) - key);
114 b_ind = (int)(index(key,b) - key);
a_row = a_ind / 5;
b_row = b_ind / 5;
a_col = a_ind % 5;
b_col = b_ind % 5;
if (j % 2 == 0){
result[i+j] = key[5*a_row + b_col];
} else {
result[i+j] = key[5*a_col + b_row];
}
}
}
result[i] = '\0';
return result;
}

最佳答案

该错误表示在 bifidcrack.c 的第 113 行和第 114 行,正在使用指针从非指针元素中进行减法。在没有看到实际代码的情况下,由于该页面不可用,我猜测存在不正确的取消引用指针。

与此场景类似的内容

int * pointer_int = 5;
int non_pointer = 4;

这就是当前的样子

int new_int = non_pointer - pointer_int;

虽然它应该看起来像这样

int new_int = non_pointer - (int*)pointer_int;

您必须打开该文件并转到这些行以查看有关更改它们的信息。

关于c - 编译C代码时出现错误C2113,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33272241/

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