Go Back   Computer Forums > General Computing > Programming
Click Here to Login
Join Computer forums Today

Thread Tools Search this Thread Display Modes
Old 01-28-2010, 03:56 PM   #1
JogaBonito1502's Avatar
Join Date: Jan 2008
Location: U.S.
Posts: 7,841
Default Dynamic 2D Arrays -- C++

Here's my problem:

I'm creating a program that will encrypt and decrypt files by arranging the content in square matrix and doing various transformations to it. I'm currently writing the header file that will contain a class with functions in it. Each function will represent a step in the encryption/decryption of the file.

My first function is very simple. It simply reads the contents of the file and decides what dimensions the square array should be.

int IndentifyMatrix();
This function will return the size of the m x m matrix.

My next function will change the characters into their respective ASCII values, and will sort them into the m x m matrix. In this definition, I need my dimensions to be left open (dynamic) because the dimensions will be sent in a variable pointer which contains the result of the function above. This is what my declaration looks like:

void Encrypt(int* MatrixSize, char const* (*inFile), int CypherMatrix[][]);
Here, I have two questions:

1. inFile needs to be a 2D array containing the characters of the text file in a M x M array (where M = the size of the matrix defined by the IdentifyMatrix()).

I could make this array 1D, but if I do so, I want to load the contents of the text file into the program and make this 1D array a pointer.

I also want the values of this 2D (or 1D pointer) array to be constants (so they can't be toyed with while the program runs).

2. CypherMatrix needs to be a dynamic array (one without the dimensions defined) until I run IdentifyMatrix(). As stated earlier, IdentifyMatrix() will return me a value with the dimensions of the square matrix. How do I declare this dynamic 2D array (this NEEDS to be 2D so I can do matrix transformations).

Thanks for the help.
JogaBonito1502 is offline   Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

All times are GMT -5. The time now is 09:14 PM.

Powered by vBulletin® Version 3.8.8 Beta 4
Copyright ©2000 - 2019, vBulletin Solutions, Inc.
Search Engine Friendly URLs by vBSEO 3.6.0