title: strcpy 2D Array problems in functions
body: <p>May I ask what is wrong with my code? strcpy seems to be working only inside the function. But when I'm passing it to another function, the first array prints okay but the other ones don't print correctly?</p>
  
  <p>What seems to be the problem with my code and what is the correct way?</p>
  
  <p>Here is the code:</p>
  
  <pre><code>void copyString(char *data, int ctr){
     int i;
     char constData[10][50] = {{"Hello"}, {"Goodbye"}, {"Konichiwa"}, {"Sayonara"},
                               {"Ni Hao"}, {"Zai Jian"}, {"Annyeong Haseyo"},
                               {"Annyeonghi Gaseyo"}, {"Bonjour"}, {"Au Revoir"}};
     char temp[50][100];
  
     strcpy(temp[ctr], constData[ctr]);
  
     if (ctr == 4)
        for(i = 0; i &lt;=ctr; i++)
            printf("In function: %s\n", temp[i]); 
  
     strcpy(&amp;data[ctr], temp[ctr]);
  }
  
  int main() {
     int i = 0, ctr = 0;
     char data[20][10];
  
     for (ctr = 0; ctr &lt;= 4; ctr++)
         copyString(data[ctr], ctr);
  
     printf("\n");
     for(i = 0; i &lt;= 4; i++)
           printf("%s\n", data[i]);
  
     return 0;
  }
  </code></pre>
  
  <p>The output gave me this:</p>
  
  <blockquote>
    <p>In function: Hello<br>
    In function: Goodbye<br>
    In function: Konichiwa<br>
    In function: Sayonara<br>
    In function: Ni Hao<br>
    <br>
    Hello<br>
    <br>
    <br>
    a<br>
    a<br></p>
  </blockquote>
  
  <p>But the output should be like this:</p>
  
  <blockquote>
    <p>In function: Hello<br>
    In function: Goodbye<br>
    In function: Konichiwa<br>
    In function: Sayonara<br>
    In function: Ni Hao<br>
    <br>
    Hello<br>
    Goodbye<br>
    Konichiwa<br>
    Sayonara<br>
    Ni Hao<br></p>
  </blockquote>
  
  <p>Thank you in advance!</p>