Search code examples
coracle-pro-c

How can I pass array of pointers between my functions in C?


I am biginner in C and PRO*C and need some help. I have a structure as below:

  typedef struct pt_st{
   char (*s_no)[100];
   char (*s)[100];
    } pt_st;

I have a function like c_info which calls post function:

int c_info(pt_st ir_st)
{
int   li_result = 0;
li_result = post(ir_st.s_no)
} 

and post function is :

int post(char *is_st)
{
//do something
}

When I compile my program , I get three errors:

warning: passing arguments post from incompatible pointer type
warning: passing arguments post make integer from ponter without cast
warning: passing arguments post make ponter from integer without cast

Does anyone kow how can I fix this?

Thank you!


Solution

  • pt_st.s_no as well a pt_st.s both declare a pointer to an array of char.

    So the function post() needs to expect such, like:

    int post(char (*s_no)[100]);
    

    If the shown definition of int post(char * is_st) cannot be changed, then call it like this:

    pt_st s = ... /* some initialisation */
    
    int result = post(*(s.s_no));