Code:
int initialise(int numofteams) {
char *yes = "y";
char *no = "n";
int tmp_y;
int tmp_n;
char yesno[1];
printf("\nDo you want to read data from a file? (y/n)\n>");
scanf("%s", yesno);
tmp_y = (strcmp(yesno, yes));
tmp_n = (strcmp(yesno, no));
/** if reading from a file... **/
if (tmp_y == 0) {
printf("you entered yes");
read_file();
}
/** if not reading from file... **/
if (tmp_n == 0)
{
int i;
for (i = 0; i < numofteams; i++)
{
char teamd[16];
printf("\nPlease enter team name:\n>");
scanf("%s", teamd);
char target[16] = "teamd";
int j;
for (j = 0; j < i; ++j)
{
int comptname;
comptname = (strcmp(teamd, arrdetails[j].team));
if (comptname == 0)
{
printf("Sorry, this team already exists. Please try again!");
i--;
}
if (comptname != 0)
{
strcpy(arrdetails[num_teams].team, teamd);
arrdetails[num_teams].played = 0;
arrdetails[num_teams].won = 0;
arrdetails[num_teams].lost = 0;
arrdetails[num_teams].draw = 0;
arrdetails[num_teams].points = 0;
arrdetails[num_teams].goalsfor = 0;
arrdetails[num_teams].goalsagainst = 0;
arrdetails[num_teams].goalsd = 0;
arrdetails[num_teams].team_id = num_teams;
num_teams++;
}
}
}
}
return 0;
}
The problem code is where it checks if the team is already in the array. it just doesnt function correctly.
Any ideas why its not functioning correctly?