OK, so I am writing a flashcard script for the command prompt (hence, all of my other questions). I had the script working fine, except for the fact that when I displayed a question (or answer) that was more than 1 line long, then it would break in the middle of the word. So I tried to fix this by dividing the question/answer into lines of 73 chars (or less), and then display it line by line.
here is what I came up with:
[code=cpp]
vector<string> q;
int qsize = ((question.leng th()/73) + 1);
switch (qsize)
{
case 1:
q.push_back(app end(question," ", 73));
break;
default:
int temp = 73;
int temp2 = 0;
while (temp < (question.lengt h()+73) )
{
temp = question.rfind( " ", temp);
q.push_back(app end(question.su bstr(temp2,temp )," ", 73));
temp2 = temp+1;
temp = temp + 73;
}
break;
}
[/code]
Append function:
[code=cpp]
//Append function: only works well with append strings of length 1.
string append(string str, string app, int length)
{
while(str.lengt h()<length)
{
str = str + app;
}
return str;
}
[/code]
It compiles fine (under Dev-C++), and will display a question with a length of only one line just fine. However, it will not display any questions that are multiple lines. The program just freezes, and sits there. Can anyone tell me why?
here is what I came up with:
[code=cpp]
vector<string> q;
int qsize = ((question.leng th()/73) + 1);
switch (qsize)
{
case 1:
q.push_back(app end(question," ", 73));
break;
default:
int temp = 73;
int temp2 = 0;
while (temp < (question.lengt h()+73) )
{
temp = question.rfind( " ", temp);
q.push_back(app end(question.su bstr(temp2,temp )," ", 73));
temp2 = temp+1;
temp = temp + 73;
}
break;
}
[/code]
Append function:
[code=cpp]
//Append function: only works well with append strings of length 1.
string append(string str, string app, int length)
{
while(str.lengt h()<length)
{
str = str + app;
}
return str;
}
[/code]
It compiles fine (under Dev-C++), and will display a question with a length of only one line just fine. However, it will not display any questions that are multiple lines. The program just freezes, and sits there. Can anyone tell me why?
Comment