struct pointer作为参数并返回

时间:2014-01-17 08:11:32

标签: c pointers struct

我有一个函数,它将一个struct指针作为参数并返回它。我希望另一个函数的函数填满由指针指向的内存。我的代码是

struct my_struct{
unsigned char** ps;
unsigned long*  pl;
};

struct* function(struct* param){

   another_func(param->ps,param->pl)//function takes pointers as parameters and fills them  up 
   return param;
 }

int main{
my_struct *p;
p=function(p);
}

//definiton of another func is;

void another_func(unsigned char**,unsigned long * ){...}

编辑:它提供错误访问冲突

1 个答案:

答案 0 :(得分:1)

从目前为止发布的内容中尝试改为:

typedef struct my_struct 
{
  unsigned char** ps;
  unsigned long*  pl;
} my_struct;

void another_func(unsigned char**,unsigned long * ) {...}

my_struct* function(my_struct* param)
{
   another_func(param->ps,param->pl)
   return param;
}

int main()
{
  my_struct *p;
  my_struct q = {NULL,NULL};
  unsigned long pl = 10;
  q.ps = malloc( pl * sizeof(char*) );
  q.pl = &pl;
  p=function(&q);
  return 0;
}

聊天后编辑