fgets
stores the \n
and then stops taking input.
So suppose a player name is "user"
, players[i].name
will be equal to "user\n"
while a
is "user"
.
So return of strstr
is always NULL
.
Try this instead:
p = strstr(players[i].name,a);
OR, remove the \n
after taking input from file by fgets
:
while(fgets(line, 100, fp)!=NULL)
{
players[i].no=i;
strcpy(players[i].name, line);
players[i].name[strlen(players[i].name)-1]='\0'; //add this line
fprintf(stdout, "\nplayer=%s", players[i].name);
players[i].age=20;
i++;
}