2012-11-28 21 views
0

我又回到了另一段錯誤,我似乎無法征服。生產者/消費者模型中的SegFault

我弄清楚它到底是什麼,它是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

回答

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); 
+0

它總是愚蠢的。謝謝 –