Original Post
Hi, I have a long std::string which I want to split in to fixed-size smaller ones. Essentially my goal is displaying the source string in broken lines according to the width of my screen. My code could have many mistakes because I am relatively new to this, please correct me as you feel right. [smile] My string is string error_msg_local, and I have also determined the maximum int chars_on_a_line. Therefore if numlines is the number of lines my text will span,
numlines = (int) strlen (error_msg_local.c_str()) / chars_on_a_line + 1;
Does this make sense? Also,
char lines[numlines][chars_on_a_line + 1]; Where lines[0], lines[1] will be pointers to the start of each line. At present I am using strncpy (lines[0], error_msg_local.c_str(), chars_on_a_line); but the last character in lines[0] as displayed is a garbage value, which was never there in error_msg_local. I have allotted enough space for the characters, so what is happenning? My next problem is finding out lines[1], lines[2], etc. Is there any function I could use here? I will also eventually run into the problem that words will be broken in half as the string is split up. Is there any way I can make it split only at the ' ' (space) characters? Thanks a lot for any help!