Characters per line

So, thanks to your help, I have this code for encrypting. But, to make it look nicer, I'd like to limit the characters per line to 50 (and just for a bit of practice at well). I thought i had it with an if statement and a counter at the end. The first line seems to work correctly, but after that it gets pretty messy. I'd like maybe some advise or something to lead me in the right direction to getting this right.
Thanks for anything though!
Code:
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <iostream>
#include <fstream>

using namespace std;

int main()
{
    ifstream fin;
    fin.open("eFile.txt");
    if(!fin)
    {
        cout << "Program is terminated - cannot locate input file";
        cout << " or wrong file name.";
        return 1;
    }
    int space_index = 0;
    int counter = 1;
    char letters[]  = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    char encryptL[] = "EMNVDLWAUCPOKXQBIZJRYTGSHF";

    char numbers[]  = "0123456789";
    char encryptN[] = "9876543210";

    char special[]  = "!$%&'()*+,-./;<=>?@[]}{";
    char encryptS[] = "{}][@?>=<;/.-,+*)('&%$!";
    char encryptSpace[] = "^~#`:";

    while (true)
    { if (counter == 50)
        {
            counter = 1;
            cout << endl;
        }
      else

      {
        char data;
        fin.get(data);

        if( !fin ) break;

        data = toupper(data);

        if (data >= 'A' && data <='Z')
        {
            for (int i = 0; i < sizeof(encryptL); ++i)
            {
                if( data == letters[i] )
                {
                    cout << encryptL[i];
                    break;
                }
            }
         }
         else if( data >= '0' && data <= '9')
         {
             for( int i = 0; i < sizeof(encryptN); ++i)
             {
                 if( data == encryptN[i] )
                 {
                     cout << numbers[i];
                     break;
                 }
             }
         }
         else
         {

             bool character_found = false;
             for( int i = 0; i < sizeof(encryptS); ++i)
                {
                 if( data == encryptS[i])
                 {
                     character_found = true;
                     cout << special[i];
                     break;
                 }
                }

             if( character_found == true)
                 continue;

                 if( data == ' ')
                {
                    cout << encryptSpace[space_index];
                    space_index = (space_index + 1) % sizeof(encryptSpace);
                    continue;
                }


             if( character_found == true)
                 continue;
             else
                 cout << data;

                          }
                        }
         counter++;
                      }
        fin.close();
        return 0;}

Last edited on
Can you explain what is happening which isn't supposed to happen?

And what you want to happen?
Like is it 'prompt if above 50characters' ? Then your if statement seems alright to me you just need a break.
Last edited on
So i basically want like an even block of characters at 50 characters per line. But instead I'm getting the first line right then the next line outputs 14 characters, the next one 33, ect.
When i break it just gives me the first line of code.
Edit: I figured it out, thank you though!
Last edited on
Topic archived. No new replies allowed.