gpt4 book ai didi

c++ - 段错误(怎么了,strcpy)

转载 作者:太空宇宙 更新时间:2023-11-04 15:09:26 26 4
gpt4 key购买 nike

在 GDB 中我得到:

 (gdb) backtrace0  0xb7d91544 in strcpy () from /lib/libc.so.61  0x08048982 in ISBN::ISBN(char const*, ISBNPrefix&) ()2  0x08048d4a in main ()(gdb)

From this code:

ISBN::ISBN(const char* str, ISBNPrefix& list) {
if(isValid(str)) {
isSet = true;
sprintf(*isbnStr,"%s",str);
}
}

究竟是什么原因造成的?

isbnStr 在头部创建:

class ISBN
{
...
char* isbnStr[11];
...

关于我在这里做什么会导致这个段错误有什么想法吗?

main 中的调用是:

ISBN* isbn = new ISBN("7999999008",*prefix);

最佳答案

isbnStr 是一个字符串数组(或者更具体地说是字符指针),而不是一个字符数组。我想你是想做 char isbnStr[11];

关于c++ - 段错误(怎么了,strcpy),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5201440/

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