HI!
I have a 2D array. It is 20 columns of 20 ints (20x20).It contains only values from 0 to 9.
I am/have been attempting to use this 2D array of int to initialise a 20x21 array of char. I also want to replace the associated integer (0 to 9) with a corresponding character ('A' to 'J'). ie) A = 0 etc.
I am kinda on my way to achieving this part but I also need to have a null terminating character as the 21st character of each column.
This is what I've done so far... It isn't working yet - Please Help!!!
Code:
#include <stdio.h>
#define MAX 20
main()
{
int my_array[MAX][MAX] = {
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
{ etc. etc. etc. }
};
int i = 0, j, x;
char my_arraystr[MAX][MAX + 1];
for (i=0; i < MAX; ++i)
{
for (j=0; j < MAX; ++j)
{
my_arraystr[i][j] = my_array[i][j];
for(x='A'; x < 'K'; ++x)
{
my_arraystr[i][j] = x;
}
}
}
for (i=0; i < MAX; ++i)
{
for (j=0; j < MAX; ++j)
printf("%c", my_arraystr[i][j]);
putchar('\n');
}
}
Anyone have any help or advice as what I can do to solve this problem and to add the null character. As it stands, this will compile and run but it doesn't display (0 - 9) as (A - J) and I don't know what to do about the 21st element of each line?
Help please
Thanks