When .llN appears, create a new paragraph

Im supposed to create a text formatter that reads input from one file and formats it to 60 characters per line in another file. If a word needs to be split up, it can be done by inserting a "-". Paragraphs cannot end in a white space. Random spaces can be added between words to make it 60 characters per line. Whenever the ".llN" appears, i am supposed to create a new paragraph. One major bug is that some lines end in 59 characters. Also I am struggling to understand how to do the .llN part, please help

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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# include <cstdlib>
# include <iostream>
# include <iomanip>
# include <fstream>
# include <ctime>
# include <cstring>

using namespace std;

int main(int argc, const char * argv[])
{
    char space =' ';
    string para = ".llN";
    string c="";
    string previousC;
    string str;
    int wordnum=0;
    int length =60;
    int counter =0;
    
    ifstream file;
    ofstream test;
    file.open("test.txt");
    test.open("answer.txt");
    
    while(getline(file, str))
    {
        for(int i=0;i<str.length();i++)
        {
            if(c.length() ==0 && isspace(str[i]))
            {
                test<<"";
            }
            else if(c.length()<= 60 && str.find(para)==true)
            {
                if(str[i] == '.' && str[i+1] =='l' && str[i+1] =='l' && str[i+1] =='N')
                    test<<"\n";      
            }
            else if(c.length()+1 == 60 && str[i] != space && str[i+1]!= space)
            {
                test<<c<<"-\n";
                c="";
            }
            else if(c.length()+1 == 60)
            {
                test<<c<<"\n";
                c="";
            }
            else
                c+=str[i];
        }
    }
    test<<c<<"\n";
    return 0;   
}

Test File I created:
Yeah, this album is dedicated to all the teachers that told me I'd never amount to nothin', to all the people that lived above the buildings that I was hustlin' in front of that called the police on .llN me when I was just tryin' to make some money to feed my daughter, and all the fellas in the struggle, you know what I'm sayin'?

After my code runs:  
Yeah, this album is dedicated to all the teachers that told
me I'd never amount to nothin', to all the people that live
above the buildings that I was hustlin' in front of that ca-
led the police on .llN me when I was just tryin' to make so-
e money to feed my daughter, and all the niggas in the stru-
gle, you know what I'm sayin'?

Expected to run: 
Yeah, this album is dedicated to all the teachers that  told
me I'd never amount to nothin', to all the people that  live
above the buildings that I was hustlin' in front of that ca-
led the police on 
me when I was just tryin' to make so-
e money to feed my daughter, and all the niggas in the stru-
gle, you know what I'm sayin'?
Last edited on
Take a look at line 36:

if(str[i] == '.' && str[i+1] =='l' && str[i+1/*Note*/] =='l' && str[i+1/*Note*/] =='N')

I would think that the 1 shouldn't appear that often.
Topic archived. No new replies allowed.