Why this code not working
#include <stdio.h>
#include <stdlib.h>
int main()
{
char **orderedIds;
orderedIds = malloc(3 * sizeof(char*));
for (int i = 0; i < 3; i++){
orderedIds[i] = malloc((10) * sizeof(char));
char name[10];
printf("Enter name %d: \n",i);
scanf("%s",&name);
orderedIds[i] = name;
printf("%s\n",orderedIds[i]);
}
printf("element is %s\n",orderedIds[0]);
}
Every element is the last element in the array i dont know why its not working plz help this is the output
Enter name 0:
john
john
Enter name 1:
guy
guy
Enter name 2:
some
some
element is some
some should be the last element but its the first why?