Here I want to save input string by pointing to an array, but the output will all change to the last inserted input.
char **month;
int row, col;
int i, j;
char name[10];
month = (char **)malloc(3*sizeof(char *));
for (int i = 0; i < 3; i++)
{
month[i] = (char *)malloc(10*sizeof(char));
printf("Enter name\n");
scanf("%s", name);
month[i] = name;
}
for (int i = 0; i < 3; i++)
{
printf("%s\n", month[i]);
}
return 0;
Any idea how can I fix it?