If I have an array, like:
char array[10][20];
then it is an array of 10 strings, each of length 20. If I make a similar array with malloc:
char **dyn_array = (char **) malloc(10 * sizeof(char *));
then how do I access the members? For example, if I had a loop like:
int limit, count=0;
printf("Enter the limit (max 10): ");
scanf("%d", &limit);
fflush(stdin);
while(count < limit)
{
int index = 0;
printf("\nEnter characters: ");
fgets(array[count], sizeof(array[count]), stdin);
fflush(stdin);
printf("\nYou typed: ");
while(array[count][index] != '\n' &&
array[count][index] != '\0')
{
printf("%c", array[count][index]);
index += 1;
}
count += 1;
}
could I replace array with dyn_array in every spot and have it be the same? What changes would I have to make? I know that the way these two kinds of arrays work is similar, but I just can't wrap my head around it.