将指针传递到一个弹力中
Passing and realloc a pointer into a funcion
嗨,我有一个我想在funciont中操纵的指针,因此我将双重指针用作函数的参数。.问题是,当它调用Realloc时,生成了segmantation故障..这里有我的代码
Loader::Loader(char* filename)
{
file_desc=open(filename,O_RDONLY);
if(file_desc<0) {
std::cout<<"Error to open file..."<<std::endl;
}
offsets=(int*)malloc(sizeof(int));
this->detect_element(&offsets,'o',0);
}
void Loader:: detect_element(int** off,char p,int loffset,int end)
{
char buffer;
int count=1;
int i=0;
std::cout<<"Starting with caracter "<<p<<" from "<<loffset;
if(end!=-1)
{
std::cout<<" and ending to "<<end<<std::endl;
}else{
std::cout<<" and ending to the end"<<std::endl;
}
lseek(file_desc,loffset,SEEK_SET);
while(read(file_desc,&buffer,1)>0)
{
if(buffer==p && state==CR)
{
*off[count-1]=i;
*off=(int*)realloc(*off,
sizeof(int)*(++count));
}
else if(buffer=='n'){
state=CR;
}
else{
state=-1;
}
i++;
if(end!=-1&&end==i){break;}
}
std::cout<<"Number of objs detected is "<<this->Length(*off)
<<count<<std::endl<<std::endl;
}
i使用称为int*的函数中的另一个指针求解,而我将其与之合作。到最后,我写 *off = offe;它起作用
相关文章:
- 修改函数中的指针(将另一个指针作为参数传递)
- 将指针分配给另一个指针时会发生什么情况?
- C++将一个指针分配给另一个指针时执行的类型检查
- 更改一个指针后更改乘法对象
- 从另一个指针指向函数的指针
- 有没有办法在同名类 (c++) 中为对象分配一个指针变量
- 为什么通过定义另一个指针单元格,整个代码停止工作?
- C:试图将指针值复制到另一个指针中,得到可修改的左值错误
- C++ typedef 函数指针,并在一个语句中声明一个指针
- 一个对象的两个指针.删除了一个指针,对象仍然存在
- 如何获得GUID编码器,如果我在IMFTransform上有一个指针?
- 我不明白我的错误需要返回一个指针数组
- 使用 SFINAE 测试是否可以将一个指针类型static_cast到另一个指针类型
- 将指针分配给另一个指针时会发生什么情况?
- 如何保存指针地址,以便另一个指针可以继续处理它
- 为什么 std::span 是一个指针 + 大小而不是两个迭代器
- 类的成员应该是一个指针
- 隐式指针变量,在自动定义中具有另一个指针变量
- 利用双重链接列表中的下一个指针
- 你能把一个指针投射到数组中吗?