0

我带着另一个我似乎无法克服的段错误回来了。

我已经弄清楚它到底是什么,它与 char* 字符串线有关。我用它来分解字节以获取此 pdf 文件以用于学校作业。

任何和所有的帮助表示赞赏!

void* consumer(void *temp)
{
int* stuff = reinterpret_cast<int*>(temp);
int x = *stuff;
char* string[];
stringstream stream1;
stringstream stream2;
int temp1=0;
int temp2=0;
int sent1=0;
int sent2=0;
ofstream fout;

strcpy(string,request); //SEGFAULT(11) ON THIS LINE, WHEN CALLING "string"
strcat(string,"Byte Range: ");
...

完整的代码可以在这里找到;https://www.dropbox.com/sh/dt90ot3z4v5nruy/1H9a5Cyb5A mgetweb.h 和 mgetweb.cpp

4

1 回答 1

1

您还没有new字符串指针的内存,访问它是未定义的行为。

//  char* string[]; I guess that's not what you intent to do, declaring an array of pointers?

char* string = new char[BIG_ENOUGH_SIZE];
strcpy(string, request);
于 2012-11-28T01:06:47.460 回答