I have the following program to take five user entered names and print them out.
I need to ask for each name one by one, then prompt the user to either print the list of names or add another name to the list. The names must be stored in a two dimensional array, though I don't see why it couldn't be done with a regular array.
My code accepts the names with no issues, but fails to print anything. It includes print tests to monitor where the error happens. Test number 6 does not print, so there must be an issue with printf("Name: %s", names[x][y]);
What is the error?
#include <stdio.h>
int main() {
int x;
int y;
char names[5][51] = {{'\0'},{'\0'}};
printf("Enter the names: ");
for (x = 0; x <5; x++) {
printf("\nPrintTest 1");
for (y = 0; y < 1; y++) {
printf("\nPrintTest 2");
scanf("%50s",&names[x][y]);
}
}
printf("\nPrintTest 3");
for (x = 0; x < 5; x++) {
printf("\nPrintTest 4");
for (y = 0; y < 1; y++) {
printf("\nPrintTest 5");
printf("Name: %s", names[x][y]);
printf("\nPrintTest 6");
}
}
}