I suggest you to profitably use the
C
library function
strncmp[
^]. Try for instance
#include <stdio.h>
#include <string.h>
struct cricket
{
char country_name[50];
char player_name[50];
int batting_average[50];
};
int comp_cricket_names(struct cricket * pc1, struct cricket * pc2)
{
int c = strncmp( pc1->country_name, pc2->country_name, sizeof(pc1->country_name));
if ( c == 0 )
c = strncmp( pc1->player_name, pc2->player_name, sizeof(pc1->player_name));
return c;
}
int main()
{
struct cricket ck[3];
strcpy(ck[0].country_name, "India");
strcpy(ck[0].player_name, "Nikhil");
strcpy(ck[1].country_name, "Australia");
strcpy(ck[1].player_name, "Nikhil");
strcpy(ck[2].country_name, "India");
strcpy(ck[2].player_name, "Nikhil");
int i;
for (i=0; i<2; ++i)
{
int j;
for (j=i+1; j<3; ++j)
{
if ( comp_cricket_names(&ck[i], &ck[j]) )
printf("team %d and %d have different names\n", i, j);
else
printf("team %d and %d have same names\n", i, j);
}
}
return 0;
}