I'm having some problems with a linear search in C
The values of the strings in arrdetails.team array are:
MAX_TEAMS is equal to 12
arrdetails[0].team = manu
arrdetails[1].team = liverpool
arrdetails[2].team = 0
arrdetails[3].team = 0
arrdetails[4].team = 0
arrdetails[5].team = 0
arrdetails[6].team = 0
arrdetails[7].team = 0
arrdetails[8].team = 0
arrdetails[9].team = 0
arrdetails[10].team = 0
arrdetails[11].team = 0
I am looking for the FIRST position of 0, in the case above it should be 2.
Please help me get this working
Thanks
The values of the strings in arrdetails.team array are:
MAX_TEAMS is equal to 12
arrdetails[0].team = manu
arrdetails[1].team = liverpool
arrdetails[2].team = 0
arrdetails[3].team = 0
arrdetails[4].team = 0
arrdetails[5].team = 0
arrdetails[6].team = 0
arrdetails[7].team = 0
arrdetails[8].team = 0
arrdetails[9].team = 0
arrdetails[10].team = 0
arrdetails[11].team = 0
I am looking for the FIRST position of 0, in the case above it should be 2.
Code:
int linear_search() {
printf("\n **LINEAR SEARCH** \n");
//find next team pos
int i;
char target[1];
target[1] = "0";
int tm_comp;
for (i = 0; i < MAX_TEAMS; i++) {
printf("\nfound pos is called %s",arrdetails[i].team);
tm_comp = (strcmp(arrdetails[i].team, target));
if (tm_comp == 0) {
printf("\nfound pos is %d \n",i);
return i;
}
}
printf("\nfound pos is %d \n",i);
}
Please help me get this working
Thanks