2d array.. help

Write your question here.
how to take out an array index permanently ?
You can't. Plain arrays have fixed size and removing an element would change its size.
You have to create a new array of size oldsize-1 and skip that index when copying the data over.
can you please show me how??:)
because i'm trying to create a 2d array with type 'int' and put it inside a for loop,what will happen is first take out a randomized index number (of course using 'rand()' )...then replace that index with a 'm' or any letter.....
if you can take sometime and do that i appreciate it big time.
I'm not sure I understand... you want to replace a numerical index with a letter?
An integer array cannot hold strings (not entirely true of characters, but another topic altogether), but you can get your output to treat certain numbers as letters according to your own rules easily enough.
1
2
3
4
5
6
7
8
9
10
11
int array[y][x];
/*loops and rand commands here...*/

if (array[y][x]==0)
cout<<" ";
else if (array[y][x]==1)
cout<<"M";
else if (array[y][x]==13)
cout<<"X";
else
cout<<array[y][x];

So you could use loops and rand to play with the array values, and depending on what you want to do have it output various things based on the values stored. There is another way, which involves the use of character codes, but then you would have to flag another variable on and off and use if/else to control when to output as an int or as a char.
1
2
3
4
5
6
7
8
9
int c=0;
int array[y][x]={};
//loops and rand stuff here
//turn c to 1 in the loop somewhere when desired

if (c==0)
cout<<array[y][x];
else
cout<<(char)array[y][x];

If the array position specified were equal to 3, for instance, c being 1 or 0 would be the difference between the number 3 and the heart symbol, but there is a character code for every symbol and you can check it out here:http://www.theasciicode.com.ar/
Not all symbols, such as the card suits at 3,4,5, and 6 are represented here, but I can confirm the vast majority of them.
Last edited on
thank you both guys but i want to build a game (tic tac toe) :)
-------0 1
0 || m || z || 9
1 || 4 || z || 5
2 || 5 || m || 2
and i have an idea that's why i'm asking,which is that whenever you choose a rw or a column it will type the a letter of the users name thats been previously entered ...
ps:i'm practicing arrays now so please make the answer in that area.
thank you very much,appreciate it.
Last edited on
What if the two users have the same start letter or name?
it'll not be accepted through while (true) statement , or any other statements
Topic archived. No new replies allowed.