Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>In short, it looks like you need to brush up on your pointers. With your original print function:</p> <pre><code>void print(char *a) { int i=0; printf("the list of names include : \n"); while(*(a) != '\0') { printf("%s\n", *(a+i)); i++; } } </code></pre> <p>You are printing the value at a + i every iteration. This might sound like what you want, but what you <em>actually</em> pass to <code>print</code> is a pointer to an array of arrays of char (your compiler should be throwing a warning about incompatible pointer types). That is, the "proper" type of <code>ps</code> is <code>(char *)[]</code>. So in the <code>print</code> function you are only advancing the memory address by sizeof(char) with each iteration, whereas what you actually want is to increment it by sizeof(char) * maxx (the size of your array entries). To implement this change, do the following:</p> <ol> <li>change declaration of <code>print</code> <ul> <li><code>void print(char (*)[maxx]);</code></li> </ul></li> <li>change to proper pointer type <ul> <li><code>char (*ps)[maxx] = input;</code></li> </ul></li> </ol> <p>And finally, change print function to something like:</p> <pre><code>void print(char (*a)[maxx]){ printf("the list of names include : \n"); int i; for (i = 0; i &lt; lim; i++){ printf("%s\n",*a); a++; } } </code></pre> <p>You need not use the (a+i) syntax, as just advancing a by one each iteration accomplishes the same thing, and is possibly faster for large i. And of course, as others have mentioned, double check your new line printing, I believe you want <code>printf('\n')</code>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload