Hi, Im currently trying to write a program to model the "Weasel" evolution model, described here: Weasel program - Wikipedia, the free encyclopedia
This basically consists of setting a target phrase, then, starting from a completely random phrase, "evolving" that random phrase towards the target phrase
The program itself seem to work fine, but I'm having a bit of difficulty with my output. Im using FLTK for the GUI, which cant handle normal strings, but requires converting them via Im outputting a new phrase, in the form of a c-string every 0.01 seconds by appending it to a buffer, which is then output in a text box.
My problem is that, seemingly randomly, when I use c_str(), the original string will become truncated, but this only ever happens where there is a space (not always the first space either):
Str: "1 2 3 4 5 6 7 8 9 0 { }...etc" <-multiple spaces in string
C-str "1 2 3 4 5"
Since this seems to happen seemingly randomly, I am at a loss as to what it might be, and google wasn't much help!
The particular code that converts the strings and adds them to the buffer is here:
Code:
cout << "\nGen Num: " << gn;
e1.setphrases(e1.breed()); //Generates new phrases
string o = "\n Best from generation ";
o.append(intstr(gn)); //Append Number of generations thus far
o.append(" is: ");
cout << e1.getHiScr(); //Get random phrase closest to target phrase
o.append(e1.getHiScr()); //Append this to o
cout << "\nNrm: " << o; //Testing difference
cout << "\n Cstr: " << o.c_str(); //between original and converted
progress->value(e1.getScr(e1.getHiScr())); //Update progress bar
phrsbuff->append(o.c_str()); //Convert string o created above to cstr, append to text buffer
outputbox->buffer(phrsbuff); //Put buffer in output box
outputbox->redraw(); //Refresh box
outputbox->insert_position(outputbox->buffer()->length()); //Scroll output
outputbox->show_insert_position(); //box down
Fl::add_timeout(0.01, generate_cb);
Sorry to dump a big wall of text. Ill attach all the code, as its easier to see what I mean if you see the program running. Also, I'm using Quincy: Simple free C/C++ programming IDE for Windows as an editor and compiler
Thanks
Chris