This is my coplete project for anyone interested in more context: https://www.codepile.net/pile/LEYKzR0N
However I dont believe you need the whole code to answer this.
My function listGamesForPlayer reads a file that's format looks like this the file screenshot
The function scans for a name and returns only the line or lines that the name has been wrote in.
The function works perfectly fine but one problem is this. Lets say that in one line we have the name sara and in the other we have sarah. The function will display both the two names I don't want that.
So basically how can I make this code :
//this function lists all games for a player
int listGamesForPlayer()
{
FILE *fp;
char filename[]="results.txt",line[200],search_string[name];
printf("\nEnter name to search for games: ");
scanf("%s", search_string);
printf("\nID | X player | O player | Left Pieces\n\n");
fp=fopen(filename,"r");
while(fgets(line, 200, fp) != NULL){
if(strstr(line,search_string))
fputs(line, stdout);
}
fclose(fp);
return 0;
}
Only take john and not johncena. So basically to cut somehow after the last letter.
Thank you in advance.