I am creating a list of names (string in an array), but I am taking the number of names as user input, so instead of creating several variables, I am creating an array of the number of user input. So I did create a 2d array
, where one has the number of names (based on user input) & one has the string limit. So I am doing it as follows:
int numOfPatients;
printf("Enter the number of people\n");
scanf("%d", &numOfPatients);
char name[numOfPatients][30];
for (int i = 0; i < numOfPatients; i++)
{
printf("Enter person %d name\n", i + 1);
fgets(name[i], 30, stdin);
printf("%s", name[i]);
}
But this is how the output is coming
Enter the number of people
3
Enter person 1 name
Enter person 2 name
somebody
somebody
Enter person 3 name
another one
another one
the program is not allowing me to add patient 1 name for some reason. Is this is a problem with multi-dimensional arrays or fgets function?