Search code examples
ccstring

how to pass a pointer to array of strings (char *p[]) ?


I want to process an Array of strings, so it is an array of an array of chars

I've defined the strings like that

char que1[4][LEN_STRING]={{'\0'}};

and I want to pass them to the function

void print_results(char *pqueries[],document p_docs[]);

using a simple

  print_results(que1,indoc);

results in an " expected 'char **' but argument is of type 'char ( *)[30]' "

I am not even sure ive defined the function signature corrent actually,

help will be greatly appreciated

thanks


Solution

  • An array of arrays is not the same as an array of pointers. See the C FAQ more details: http://c-faq.com/aryptr/pass2dary.html.

    One solution is to modify your function to take fixed-width strings:

    void print_results(char (*pqueries)[LEN_STRING],document p_docs[]);