padding and printing 2d Array HELP PLEASE

closed account (LEwpfSEw)
I'm currently trying to build a cipher program that reads input from the user and find the nearest squared number to be used as the dimension of the 2D array. I'm supposed to fill the array with the input text from the user being read from left to right/top to bottom then print it out top to bottom/left to right so it's ciphered.

But I'm currently having trouble trying to fill the array and print it out, also how do I pad the 2D array when there are left over space?

My fill array starts at line 79. I have nested loops to read the rows and then columns but I can't seem to get the coding down for that last part. I need the help desperately!

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
104
105
106
107
108
109
110
111
112
113
114
115
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

void ReadMessage(char*, int);
void PrintMessage(const char*);
void RemoveNonLetters(char*, int);
int  FindLeastSquareRootNumber(int);
void FillArray (char*, int);
void PrintArray (char*, int);

int main()
{
    int bufsize = 500;
    char buffer[500]; // Size of Character Array

    int sqrtnumber = 0;

    char* input;
    int inputsize;

    ReadMessage(buffer,bufsize);
    PrintMessage(buffer);

    RemoveNonLetters(buffer,bufsize);
    PrintMessage(buffer);

    sqrtnumber = FindLeastSquareRootNumber(strlen(buffer));

    cout << "sqrt num: " << sqrtnumber << endl;

    FillArray(input,inputsize);
    PrintArray(input,inputsize);
}

void RemoveNonLetters(char* buffer, int bufsize)
{
    int i, j;

    for (i=0,j=0; i < bufsize; i++)
    {
        if (isalpha(buffer[i]))
        {
            buffer[j] = buffer[i];
            j++;
        }
    }
    buffer[j] = '\0';
}

int FindLeastSquareRootNumber(int number)
{
    int result = 0;

    for (;result < number; result++)
    {
        if (result*result > number) break;
    }

    return result;
}



void ReadMessage(char* buffer, int bufsize)
{
    memset(buffer,0,bufsize);
    cout << "Enter Message: ";
    cin.getline(buffer,bufsize);
}

void PrintMessage(const char* buffer)
{
    cout << endl << "Message: [" << buffer << "] " <<  endl;
}

void FillArray (char* input, int inputsize)
{

    int sqrsize = FindLeastSquareRootNumber(inputsize);

    int **CaeserBlock = new int*[sqrsize];

    for ( int r = 0; r < sqrsize; r++ ) // Loops the rows
    {
        CaeserBlock[r] = new int[sqrsize];

        for (int c = 0; c < sqrsize; c++) // Loops the columns
        {

              CaeserBlock[r][c]=input[c++];

        }

    }


}


void PrintArray (char* input,int inputsize)
{
     CaeserBlock;

    for (int r = 0; r < inputsize; r++)
    {
        for (int c = 0; c < inputsize; c++)
        {
            cout.put(CaeserBlock[c][r]) << endl;
        }
    }

}

Topic archived. No new replies allowed.