| | |
2d arrays
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Solved Threads: 0
Hi im trying to print out rows and columns using ascai characters to resemble pixels. I am trying to get the user to input the dn values for the array and then use these values to then print out the appropriate character. Im really stuck now and have been at this for days any help would be great as i have to hand this in today. Heres my code below thankyou
C++ Syntax (Toggle Plain Text)
#include <iostream> using namespace std; const int PIXEL_1 = 177; const int PIXEL_2 = 176; const int MAXROWS = 3 , MAXCOLUMNS = 3; void initalise (int pixel_array[][MAXCOLUMNS], int size_of_first_dimension); void print_array (); int main () { int num_array [MAXROWS][MAXCOLUMNS]; cout << " Please enter the DN values for num_array [0],[0]." << endl; int dn_value; cin >> dn_value; initalise (num_array, MAXROWS); for (int row = 0; row < MAXROWS; row++) { for (int column = 0; column < MAXCOLUMNS; column++) { cout << num_array[row][column] << char ( PIXEL_1 ); } cout << endl; } return 0; } void initalise (int this_array[][MAXCOLUMNS], int size_of_first_dimension) { int i = char ( PIXEL_1 ), j = char ( PIXEL_2 ); for (i = 0; i < size_of_first_dimension; i++) for (j = 0; j < MAXCOLUMNS; j++) { this_array[i][j] = char ( PIXEL_2 ); } }
This is a very weird line of code.
If you're trying to create an array of chars dynamicly you should look at new and delete
Then in the next line you say:
What should the function initalise() do exactly?
Does this even compile?
regards Niek
If you're trying to create an array of chars dynamicly you should look at new and delete
Then in the next line you say:
for (i = 0; i < size_of_first_dimension; i++) Which puts 'i' back to 0...What should the function initalise() do exactly?
Does this even compile?
regards Niek
Last edited by niek_e; Nov 19th, 2007 at 9:27 am.
•
•
Join Date: Oct 2007
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
This is a very weird line of code.
If you're trying to create an array of chars dynamicly you should look at new and delete
Then in the next line you say:
for (i = 0; i < size_of_first_dimension; i++)Which puts 'i' back to 0...
What should the function initalise() do exactly?
Does this even compile?
regards Niek
Hi
It does compile but it doesnt do what i want it to do i want to create a 2d array using the black and grey blocks from the ascii code with each dn value being either grey or black.
Perhaps I'm missing the point completly, but why not initialize your array like this:
I didn't compile it, so it might not work...
To view the content of you array you might want to try something like this:
Again: I didn't try it, it's more of a suggestion
Now all you have to do is ask the user for input and check with an IF-statement if the current value in the loop is the dn'st value (input from user)
Regards Niek
c Syntax (Toggle Plain Text)
char Screen[PIXEL_1][PIXEL_2]; for (int i = 0; i < PIXEL_1; i++) { for (int k = 0; k < PIXEL_2; k++) { Screen[i][k] = (char)178; } }
To view the content of you array you might want to try something like this:
c Syntax (Toggle Plain Text)
for (int i = 0; i < PIXEL_1; i++) { for (int k = 0; k < PIXEL_2; k++) { cout << Screen[i][k]; } cout << endl; } cin.get();
Again: I didn't try it, it's more of a suggestion
Now all you have to do is ask the user for input and check with an IF-statement if the current value in the loop is the dn'st value (input from user)
Regards Niek
Last edited by niek_e; Nov 19th, 2007 at 9:59 am.
•
•
•
•
Hi
It does compile but it doesnt do what i want it to do i want to create a 2d array using the black and grey blocks from the ascii code with each dn value being either grey or black.
1) what the program did
2) what you expected
3) where in the program we should look
Don't leave it up to us to read you code and figure out what's wrong. We need details.
The 3 Laws of the Procrastination Society:
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
1) Never do today that which can be put off until tomorrow
2) Tomorrow never comes
![]() |
Similar Threads
- (reformatted) How to return Multi-Dimensional Arrays (C++)
- What relation does **indirection operator have with Multidimensional Arrays (C++)
- Arrays (C++)
- How to Return Multidimensional Arrays (C++)
- C file input/output 2D arrays. (C)
- passing arrays in visual basic (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: Receiving user input to direct program
- Next Thread: Help with finding a good use for a hash table in my program....
| Thread Tools | Search this Thread |
api array based beginner binary bitmap c++ c/c++ calculator char char* class code coding compile compiler console conversion count database delete deploy developer directshow dll download dynamic dynamiccharacterarray email encryption error file forms fstream function functions game givemetehcodez google graph gui homeworkhelp homeworkhelper iamthwee ifstream input int java lib linkedlist linker list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference rpg sorting string strings temperature template test text text-file tree unix url variable vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






