Hi guys, anyone familiar with the Markov Chain Algorithm? I've got an assignment to take the code from a C++ implementation and remove any stl features like deques and maps, but continue to use strings as my main object type. I've based my changes around a C version of the code, which really just needs to be adapted to use C++ strings instead of C char arrays.
The place I'm running into trouble is trying to initialize all my strings with the "non-word" value
"\n"
. Here's the relevant code:
...
const char NONWORD[] = "\n";
...
int main(void)
{
int i, nwords = MAXGEN;
string *prefix[NPREF]; // current input prefix
srand(time(NULL));
for (int i = 0; i < NPREF; i++)
hashadd(prefix, NONWORD);
hashbuild(prefix, cin);
hashadd(prefix, NONWORD);
hashgenerate(nwords);
return 0;
}
...
void hashadd(string *prefix[NPREF], string *suffix)
{
State *sp;
sp = lookup(prefix, 1);
addsuffix(sp, suffix);
memmove(prefix, prefix+1, (NPREF-1)*sizeof(prefix[0]));
prefix[NPREF - 1] = suffix;
}
The error I get when I go to compile the code is
"prob3.cpp:104: error: invalid conversion from `const char' to `std::string*'"
pointing to the body of the for loop in main intended to put "\n" in each field of prefix. I've tried replacing all references to NONWORD with
"\n"
but I get the same error. Does anyone have a tip to caste or convert newline as a string?
I have a feeling this is just one of several little hurdles, so if anyone wants to see more of my code to try and find a way around this problem, let me know.