Looks like you have some Assembly code mixed in with the
GetLineCount () and
GetLastText () functions. I have no idea whether those functions are correct or not. In addition, I'm not familiar enough with Windows functions and DWORD, plus I have to relearn
malloc every time I use it, which isn't often, so again, I can't comment on those two functions except to say that if there is not a good reason to use C and Assembly code, I would go with C++ code and use C++-strings rather than C-strings and use
new rather than
malloc .
I rewrote your
GetText () function so I could use and try out the
GetLastPlayerAnswer() function and as far as I can tell, it seems to work, at least if I understand correctly what it's supposed to do. Here is the program I tested:
#include <string>
#include <iostream>
#include <cstring>
using namespace std;
struct PlayerAnswer
{
const char* Player;
const char* Answer;
};
char* GetLastText()
{
char* someText = new char[8];
strcpy (someText, "Bob:Yes");
return someText;
}
PlayerAnswer GetLastPlayerAnswer()
{
PlayerAnswer pAnswer;
if(string(GetLastText()).find(':') != string::npos)
{
char* plName = strtok(GetLastText(), ":");
char* plAnswer = strtok(NULL, "\0");
pAnswer.Player=plName;
pAnswer.Answer=plAnswer;
return pAnswer;
}
pAnswer.Answer="a";
pAnswer.Player="a";
return pAnswer;
}
int main ()
{
PlayerAnswer pa = GetLastPlayerAnswer ();
cout << "player = " << pa.Player << endl;
cout << "answer = " << pa.Answer << endl;
return 0;
}
I think your best step is to really narrow down where exactly the problem is. Put some debugging statements in after the call to the
GetLastText () function and make sure it is returning what you want it to. If not, put some debugging code in to make sure that the
GetLineCount () function does what it is supposed to do. Once you narrow down the exact function where the problem is located, go from there. Like I said, your
GetLastPlayerAnswer () function appears to work to me, or at least it did with my example.