I'm tryin to search an array of structures for name. I'm comparing a char[] to a struct member with is a char[]
my struct
struct NBA_Team
{
char* name;
char conference[8];
char division[10];
unsigned short wins = 0;
unsigned short losses = 0;
float pct;
};
My search code
void searchAndTally(NBA_Team teams, char team[], bool WL)
{
int low = 0;
int high = numTeams;
int med = (high + low)/2;
bool found = 0;
if(strcmp(teams[0].name, team) == 0)
{
if(WL == 1)
{
teams[0].wins += 1;
}
else if(WL == 0)
{
teams[0].losses += 1;
}
}
if(strcmp(teams[numTeams - 1].name, team) == 0)
{
if(WL == 1)
{
teams[numTeams - 1].wins += 1;
return;
}
else if(WL == 0)
{
teams[numTeams - 1].losses += 1;
return;
}
}
while(!found && low <= high)
{
med = (high + low)/2;
if(strcmp(teams[med].name, team) == 0)
{
found = true;
if(WL == 1)
{
teams[med].wins += 1;
return;
}
else if(WL == 0)
{
teams[med].losses += 1;
return;
}
}
if(strcmp(teams[med].name, team) > 0)
{
high = med - 1;
}
else
{
low = med + 1;
}
}
}
The problem is with this line:
if(strcmp(teams[0].name, team) == 0)
It balks evertime is sees it. I think it may be because there's a pointer inthe struct declaration, but I've made similar comparisons and they worked, this is really stumping me.