编译C代码时出现错误C2113

编译C代码时出现错误C2113,c,compilation,compiler-errors,C,Compilation,Compiler Errors,我对C没有任何经验(尽管我经常使用C),但我希望编译一些C代码: 当我在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 bifi

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

当我在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:\simple包含:

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>
C:\simple>dir
驱动器C中的卷是OS
卷序列号为AA86-3F24
C:\simple目录
22/10/2015  02:50              .
22/10/2015  02:50              ..
2015年10月12日12:06 4491 BibidCrack.c
2015年10月12日12:06 7301392 qgr.h
2015年10月12日12:06 574 scoreText.c
2015年10月12日12:06 44 scoreText.h
4个文件7306501字节
2个目录14560649216个可用字节
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;
}
char*bifidDecipher(char*key,int-period,char*text,char*result,int-len){
int i,j;
char a,b;/*我们正在查看的digram*/
国际劳工组织,国际劳工组织;
int a_行、b_行;
INTA_col,b_col;
对于(i=0;ilen){
周期=len-i;
}
对于(j=0;j
错误是在BibidCrack.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;

您必须打开该文件并转到这些行以了解如何更改它们。

您引用的代码已经降低了代码的价值,如果不将索引(降低了的POSIX)更改为strchr(当前)并根据需要进行强制转换,则无法编译

例如:

 // https://www.cplusplus.com/reference/cstring/strchr/
 a_ind = (int)(strchr(key, (int)a) - (const char *)key );
 b_ind = (int)(strchr(key, (int)b) - (const char *)key );

编译:
cl/EHcs bifidcrack.c scoreText.c

引用的代码行将非常有用…添加了bifidcrack.c的一个片段,并列出了第113行和第114行。希望有帮助!需要知道什么是“索引”。如果它没有返回
字符*
,那么是的,这是一个编译错误。谢谢你的帮助。我怎么才能找到它呢?不幸的是,我没有任何C语言的经验。我没有注意到我发布的链接现在已关闭,但如果有帮助,仍然可以通过TWBM访问:对不起,链接刚刚关闭,我没有注意到。我已经添加了BibidCrack.c的一部分,其余部分可以通过TWBM访问:我不了解c,但我会尝试修改代码。感谢您的建议。因为键是指针,所以返回的任何索引都需要是指针。那是你的错误。您可以尝试在每一行的最后一个键之前添加(char*),但我添加了强制转换,编译时返回了相同的错误。如果索引与字符匹配,则返回指针;如果索引与字符不匹配,则返回NULL。。。。尝试抛出一些if语句来处理这个问题。类似于if(index(key,a)!=NULL){a_ind=(int)(index(key,a)-key);}或者{做点什么来处理它}和第114行一样。根据编译器的不同,它可能会过于谨慎。