char userChoice;
printf("Choose how you would like to search.\nEnter A to display all players information.\
\nEnter N to search a player based on name.\nEnter J to search a player based on jersey number.\
\nEnter P to search a player based on position.\nEnter your choice: ");
scanf("%c", &userChoice);
do
{
if (userChoice == 'A' || userChoice == 'a')
{
for (index = 0; index < count; index = index + 1)
{
displayPlayers(&players[index]);
}
}
if (userChoice == 'J' || userChoice == 'j')
{
int jerseyNumber;
printf("\nEnter jersey number for the player: ");
scanf("%i", &jerseyNumber);
for (index = 0; index <= MAX_PLAYERS; index++)
{
if (jerseyNumber == players[index].jerseyNumber)
{
// If the condition is met the singleDisplay function is called.
// Containing the array of struct
singleDisplay(&players[index]);
}
}
}
if (userChoice == 'N' || userChoice == 'n')
{
char playerName[LEN_NAME + 1];
printf("\nEnter name for the player: ");
scanf("%s", playerName);
for (index = 0; index <= MAX_PLAYERS; index++)
{
if (strcmp(playerName, players[index].firstName) == 0)
{
singleDisplay(&players[index]);
}
}
}
このコードのほとんどは文脈のためのものですが、私が抱えている問題は、入力したジャージーが見つからないというメッセージを出力するelse文を作成できません。問題は、else文がループの中にあり、配列のすべての数値を比較している間に何回何回でもメッセージを出力することです。IF文Cプログラミングのループの場合
Cで 'switch'ステートメントを調べるべきです。ここでうまくいくでしょう。 – lurker
'for(index = 0; index
BLUEPIXY
「else文」がありません。あなたの質問をもう一度読んでください。 –