Oh hey yall,
I'm having a problem with a program with these directions:
"
Create a program that allows a user to enter up to five names
of friends. Use a two-dimensional array to store the friends’
names. After each name is entered, the user should have the
option to enter another name or print out a report that shows
each name entered thus far.
"
Every time I choose to print out the names it doesn't print them out correctly.
And here is my code so far:
Code:
/********************************************************************
Name: <sourcename>
Author: <author>
Description: <description>
*********************************************************************/
#include <stdio.h>
void menu(void);
int menu_op = 1;
int main(void) {
char names[5][2];
printf("\tName Entry (Enter up to 5 names)\n\n");
int a = 0;
for ( ; a < 5; a++) {
names[a][0] = '\0';
names[a][1] = '\0';
}
int i = 0;
for ( ; i < 5; i++) {
if (menu_op == 1) {
printf("Enter first name and last name separated by a space: ");
scanf("%s%s", &names[i][0], &names[i][1]);
}
if (menu_op == 2) {
int j = 0;
printf("\nNames that have been entered:");
for ( ; j < 5; j++)
printf("\n\t%s %s", &names[j][0], &names[j][1]);
}
if (menu_op == 3)
break;
menu();
}
//printf("\n\t%s %s", &names[0][0], &names[0][1]);
int j = 0;
printf("\nNames that have been entered:");
for ( ; j < 5; j++)
printf("\n\t%s %s", &names[j][0], &names[j][1]);
return 0;
}
void menu(void) {
printf("\nMenu:\n");
printf("\n1 Enter another name");
printf("\n2 Show names entered");
printf("\n3 Quit");
printf("\nEnter menu option: ");
scanf("%d", &menu_op);
}