Judging from the previous posts, I don't think this is a c++ question so I'll keep it 'C' syntax to show an example of another way to do this.
Start off by putting all your 'read' stuff in it's own function:
Once the calling function has the buffer, you can check the keyboard input against the buffer-contents to see if the user gets a match on any letters then print a new string with correct letter guesses in the right positions and '*' in unguessed positions.
static char buf;
char fname = "MyFilename.ext";
//try opening file
return (char *)NULL;
getting the whole file like this isn't
a good idea for just one string...
//read-in file, don't overrun buffer...
fread(buf, 1, sizeof(buf)-1, fp);
//instead, just get the first -significant- line,
//bunp past any CRLFs on empty lines.
fgets(buf, sizeof(buf)-1, fp);
if( (strlen(buf))>2 )
//done with file
//clear and set stars buffer
memset(stars, 0, sizeof(stars));
memset(stars, '*', strlen(buf);
//print to stdout, set cursor to overwrite
//return file-buffer to caller
Using '\r' instead of '\n' will keep the console output always on the same line.
When dealing with returned buffers, it's a good idea for the caller to get it's own local copy, so rather than depending on the scope of a static variable in another function, do something like this:
Don't copy/paste any of this code and it expect it to run without errors, none of it has been checked/compiled, it's just to give you some ideas.
int main(int argv, char **argc)
printf("Read Function failed\n");
//continue processing buf...