У меня проблемы с функцией меню моей программы. Последние две части printf для меню продолжаются до следующей функции.C Проблемы с меню
Код для функции меню -
#include <stdio.h>
#include <string.h>
void enter(char names[16][20]);
void menu();
int main()
{
char names[16][20];
int i;
printf("Please enter the names of the players:\n");
/*Making the user enter 16 times*/
for (i = 0; i < 16; i++)
{
scanf("%9s", &names[i]);
fflush(stdin);
}
/*Clearing Screen*/
system("cls");
menu();
return names[16][20];
}
void menu(char names[][20])
{
int choice;
printf("Please select one of the following options:\n\n"
"Press 1 to enter game results\n"
"Press 2 to display the current round\n"
"Press 3 to display the players advancing to the next round\n"
"Press 4 to display the previous round\n"
"Press 5 to exit the program\n");
system("cls");
scanf("%d", &choice);
if(choice == 1)
{
enter(names);
system("cls");
}
}
void enter(char names[][20])
{
int result;
int score1;
int score2;
int p, c, j, l, i;
char winner[8][8];
system("cls");
for(i = 0; i < 8; i++)
{
printf("\n\n%s vs %s",names[i],names[i+8]);
score1 = 0;
score2 = 0;
for(j = 0; j < 5; j++)
{
printf("\n\nEnter game %d results, press 1 if %s won or"
" 2 if %s won :\n",(j+1), names[i], names[i+8]);
scanf("%d", &result);
if(result == 1)
{
score1++;
}
if(result == 2)
{
score2++;
}
}
}
Как-то в прессе 4 и 5 вариантов получают в следующей следующей функции
Изображение - https://gyazo.com/7e99cfb42a18d04a144d3d139409d6ec
Добро пожаловать в переполнение стека! Вы не возражаете против создания [___MCVE___] (http://stackoverflow.com/help/mcve)? –
Я честно понятия не имею, почему это происходит, но прежде чем это началось, я переместил свое меню из основного в свою собственную функцию. Я попытаюсь сузить его – Thecube
Вы не указали достаточно информации. Пожалуйста, прочитайте приведенную выше ссылку MCVE. Похоже, у вас есть повреждение памяти в коде, который вы не показывали. Как минимум вам нужно показать, как вызывается «menu», а также «enter». – kaylum