-
Notifications
You must be signed in to change notification settings - Fork 0
/
p5_void imperfectFitNormalWord.cpp
39 lines (34 loc) · 1.12 KB
/
p5_void imperfectFitNormalWord.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
void imperfectFitNormalWord(const char a[], const int lineLength, int& remainingOnLine, ostream& outf, int tokenSize)
{
//remaining set to linelength currently
//tokenSize not changed
int i = 0;
while(a[i] != '\0')
{
for(int j = i; j < lineLength && a[i] != '\0'; j++) //i will be at correct position to continue on next line
{
outf << a[i];
remainingOnLine--;
tokenSize--;
}
//added as much of token to first line: either broke out because end of line or at zerobyte
if(remainingOnLine == 0 && tokenSize != 0) //not done adding word
{
outf << endl;
remainingOnLine = lineLength;
continue;
}
else if(remainingOnLine == 0 && tokenSize == 0) //done adding word, fit perfectly on last line
{
outf << endl;
remainingOnLine = lineLength;
return;
}
else if (remainingOnLine > 0 && tokenSize == 0)
{
outf << ' ';
remainingOnLine--;
return;
}
}//end of while
}