首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >生产者/消费者模型中的SegFault

生产者/消费者模型中的SegFault
EN

Stack Overflow用户
提问于 2012-11-28 09:00:45
回答 1查看 57关注 0票数 0

我已经弄清楚它是什么了,它是char*字符串行的东西。我使用它来分解字节,以获得这个用于学校作业的pdf文件。

任何和所有的帮助是感激的!

代码语言:javascript
复制
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: ");
...
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-11-28 09:06:47

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

代码语言:javascript
复制
//  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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/13596052

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档