title: Function that returns array of strings in C
body: <p>I'm new to C and I'm currently working on a project that I need to read a list from a Json file (using <a href="https://github.com/json-c/json-c" rel="nofollow noreferrer">json-c library</a>). So, I created a function that returns an array of string (the list). I searched and I found out that to return array of string in a function you need to type something like:</p>
  
  <pre><code>char** readJson(...) {
      ...
  }
  </code></pre>
  
  <p>and in the main:</p>
  
  <pre><code>int main() {
      ...
      char** list = readJson();
      ...
  }
  </code></pre>
  
  <p>My problem is that when I create my array, in the read function, I don't declare it, I loop through the list items (from the json object) and I add the them in the list. For example, I don't:</p>
  
  <pre><code>char** list = {"...", "..."}
  </code></pre>
  
  <p>I do:</p>
  
  <pre><code>char** list;
  for (int i = 0; i &lt; LIST_SIZE; i++) {
      strcpy(list[i], json_object_get_string(json_obj));
  }
  </code></pre>
  
  <p>And when I try to print the list item after strcpy (in for loop) it closes the program.
  So, I tried to create the array like that:</p>
  
  <pre><code>char list[LIST_SIZE][MAX_CHAR];
  </code></pre>
  
  <p>And then return this:</p>
  
  <pre><code>char** final = list;
  return final;
  </code></pre>
  
  <p>And it worked. <strong>But</strong>, when I am returning the list it gives me a warning in the compiler:</p>
  
  <blockquote>
    <p>main.c:66:20: warning: initialization from incompatible pointer type [-Wincompatible-pointer-types]</p>
  </blockquote>
  
  <p>And when I try to print the list in main it crashes.</p>
  
  <p><a href="https://pastebin.com/JE8vYeUf" rel="nofollow noreferrer">Here</a> is the source code. Check it if you want.</p>
  
  <p>Please, help me.</p>