I want to make a football group with points and goals. And the name of each group must be a capital letter, so i use isupper function to check that. But it seems that my loop is wrong in somewhere. Here is my code
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
struct Team{
char TeamName[20];
int Point;
int Goals;
};
typedef struct TeamCup {
char GroupID;
struct Team team[4];
}Group;
void AddNgroup(Group g[], int *index){
int number = 0;
printf("Enter the numbers of group you want to add: ");
scanf("%d", &number);
*index += number;
int a;
for ( a = *index - number; a < *index ; a++){
do{
printf("Enter GroupID: ");
scanf("%c", &g[a].GroupID); getchar();
} while ( isupper(g[a].GroupID));
printf("Enter 4 team: \n");
for (int i = 0; i < 4; i++){
fflush(stdin);
printf("\t Team %d", i+1);
printf("\nEnter Team %d's name: ", i+1);
fgets(g[a].team[i].TeamName, sizeof(g[a].team[i].TeamName), stdin);
printf("\nEnter Team %d's Point: ", i+1);
scanf("%d", &g[a].team[i].Point);
printf("\nEnter Goals Difference: ");
scanf("%d", &g[a].team[i].Goals);
}
}
}
int main(){
Group group[8];
int *p;
int number = 0;
*p = number;
AddNgroup(group, p);
return 0;
}
Actually, I'm making a menu about adding, printing and sorting group. Here is just the adding part. The output makes me confused.
Enter the numbers of group you want to add: 2
Enter GroupID: a
Enter GroupID: A
Enter GroupID: A
Enter GroupID: F
Enter GroupID:
I tried to use
(int)g[a].GroupID < 65 || (int)g[a].GroupID > 90)
but it didn't work too.