I am new to C, and I find it too hard to convert my program from using static arrays to using dynamic allocated arrays.
This is my 3rd program (that count words etc. form a .txt file).
So what changes do I have to do to use dynamic arrays in my program instead of static arrays?
This is a part of my 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 > 0)
    {
        wrd = fscanf(myinput, "%s",arr[i]);
        i++; //counting words in a line from txt file.
    }
  wrd = i;
    for(i = 0; i < 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; 
}
Here are some functions:
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", &choice);
    return choice;
}
Here is the histogram function:
istograma(int wrd, char arr[100][50]){
    int j, i = 0, len;
    for(i = 0; i < wrd - 1; i++){
      printf(" %s ",arr[i]);
      len=strlen(arr[i]);
      for(j=0; j<len; j++){
        printf("*");
      }
      printf("\n");
    }
}
 
     
    
 
    