# multidimentional character arrays

This is a discussion on multidimentional character arrays within the C++ Programming forums, part of the General Programming Boards category; im working on a program that has me stuck. im trying to form a grid thats 10 by 10. i ...

1. ## multidimentional character arrays

im working on a program that has me stuck. im trying to form a grid thats 10 by 10. i want it to display the numbers from one to 100. i want to b able to insert a letter in place of a number later and move it around the board. i cant figure out how to get a character matrix. any ideas?

2. char matrix[10][10];

3. i have that part, that wasnt the problem, how do i go about filling it?

4. How about a loop of assignment statements?

5. Code:
```for (r=1; r<=10; r++)
{
for (c=1; c<=10; c++)
{
board[ROWS][COLS];
}
for (c=10; c>=1; c--)
{
board[ROWS][COLS];

}
}```
this is the code that i have so far. i have a separate set of loops to display it. i know im not filling it right. thats what i cant get. i need to fill my matrix with the numbers 1-100 that reverses ever other line like this:

100 99 98 97 96 95 94 93 92 91

81 82 83 84 85 86 87 88 89 90

80 79 78 77 76 75 74 73 72 71

61 62 63 64 65 66 67 68 69 70

60 59 58 57 56 55 54 53 52 51

41 42 43 44 45 46 47 48 49 50

40 39 38 37 36 35 34 33 32 31

21 22 23 24 25 26 27 28 29 30

20 19 18 17 16 15 14 13 12 11

1 2 3 4 5 6 7 8 9 10
i noticed that the numbers come up all weird, i wanted them lined up in a box. i can fill the board if its an int but i cant switch over to a char. i thank you for any help you can give me

6. you want to be able to do something like this:1 2 c 4 5

and change it to something like this

1 2 3 4 c

then you will probably want to consider a multidimensional array (or multidimensional vector) of strings because digits can be ints or char but ints can be a single digit or a series of digits (a series of digits would be equivalent to a string rather than a single char). Using either a three dimensional array (vector) of char (using C style strings) or a two dimensional array (vector) of C++ STL strings would be possible if you wanted to do this. You might be able to use a multidimensional array of single chars if you display the character set integer representation of the char at a given point rather than display the pictoral representation of the char itself (using a cast to int????), but to me that's even more confusing. A third alternative might be to have an array of unions rather than an array of simple int or char or strings, but I've never done that, so I don't even know if it's possible or not. A fourth alternative, and the approach I'd probably consider, would be to use a multidimensional array of struct/classes that contain two data members, one an int and the a char. If the instance being displayed has a valid int but not a valid char, then display the int and if it doesn't have an valid int, then it must have a valid char, so display the char.

Given different widths of char/ints in different fonts it's not a trivial task to get perfect alignment of tables on a visual display device, but it's not rocket science either. It involves a lot of tinkering with formatting output (with C style format strings or C++ ostream manipulators/etc.) to achieve the visual effect desired. For example, 100 has three digits, but 9 has only one. Therefore to line them up you would need to have each int consist of three char digits (char?) and pad the output of 9 with a leading space (or two?) and then fill the remaining (if any) digits with spaces. I have included a simple sample using * instead of spaces that I hope will allow you to better visualize the approach:

100 *99 *88
*9* *8* *7*

7. > for (r=1; r<=10; r++)
Arrays start at 0, not 1
So it would be for (r=0; r<10; r++)

8. thanks for all the input, ill have to give it try