title: How to convert static array to dynamic?
body: <p>I am new to C, and I find it too hard to convert my program from using static arrays to using dynamic allocated arrays.</p>
  
  <p>This is my 3rd program (that count words etc. form a .txt file).</p>
  
  <p>So what changes do I have to do to use dynamic arrays in my program instead of static arrays?</p>
  
  <p>This is a part of my code: </p>
  
  <pre><code>int main(int argc, char *argv[]) { 
   FILE *myinput; 
   int count=0, a, userchoice,i=0, wrd,chrct,dfw,j,b,k;
   char arr[100][50], name[0][50];
  
    printf("Ender the name of the file you want to open: ");
    scanf("%s", name[0]);
    if((myinput = fopen(name[0], "r"))==NULL)
    {
      printf("Failed to open the file!");
      exit(1);
    }
    else
    {
  printf("Reading %s.. Done!\n\n", name[0]);
  printf("%s contein: ", name[0]);
    }
    while(wrd &gt; 0)
      {
          wrd = fscanf(myinput, "%s",arr[i]);
          i++; //counting words in a line from txt file.
      }
    wrd = i;
      for(i = 0; i &lt; wrd - 1; i++)
      {
          printf("%s ", arr[i]);
      }
  printf("\n");
   while(userchoice!=5)
   {
      switch(userchoice=choice())  //choice() is a function just with a scanf.
        {
  
  
  
          case 1: wrd=countwords(myinput); break;
          case 2: chrct=coutnchar(myinput); break;
          case 3: dfw=diffrentwords(wrd,arr); break; 
          case 4: istograma(wrd,arr); break;
          default: break;
        }
   }
   results(wrd,chrct,dfw,myinput,arr,wrd);
   fclose(myinput); 
   return 0; 
  }
  </code></pre>
  
  <p>Here are some functions:</p>
  
  <pre><code>int choice(){
      int choice;
      printf("\n1: count words \n2: count characters \n3: count different words \n4: Istogramma\n5: Save and exit\n");
      printf("enter choice:\n");
      scanf("%d", &amp;choice);
      return choice;
  }
  </code></pre>
  
  <p>Here is the histogram function:</p>
  
  <pre><code>istograma(int wrd, char arr[100][50]){
      int j, i = 0, len;
  
      for(i = 0; i &lt; wrd - 1; i++){
        printf(" %s ",arr[i]);
        len=strlen(arr[i]);
        for(j=0; j&lt;len; j++){
          printf("*");
        }
        printf("\n");
      }
  }
  </code></pre>