且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

访问冲突读取位置 (Visual Studio C++)

更新时间:2022-06-19 06:08:03

从您的代码看来,您的意图是将 sub[0] 连接到 S.简单的解决方案是删除 for 循环并简单地编写.

As it seems from your code that your intent is to concatenate sub[0] to S. Simple solution will be remove for loop and simply write.

strcat(sub[0],S);

您代码中的问题是strcat(sub[0],(char*)S[j-1]);,您试图将 char 转换为字符指针.

Problem in your code is strcat(sub[0],(char*)S[j-1]);, you are trying to cast char as character pointer.

现在我在您的代码中看到的另一件事是您还没有从第 0 个索引开始访问 S.这可能是您的要求.如果您想从 index 1 进行连接,即使这样也有解决方案.

Now other thing which I see in your code is you havn't started accessing S from 0th index. That might be your requirement or so. Even that has solution if you want to concatenate from index 1.

strcat(sub[0],&S[1]);

PS:strcat的签名是

PS: signature of strcat is

char * strcat ( char * destination, const char * source );