# Thread: Convert int array to string!

1. ## Convert int array to string!

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.

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?

Thanks

2. int i = 5;
char a = 'A' + i;
try to examine a using different values for i

Code:
```for (j=0; j < MAX; ++j)
{
my_arraystr[i][j] = ...
}
my_arrstr[i][MAX] = 0;```

3. Hi!

Ive been playin round withit! gettin really frustrated. This is my latest version - (lol still not working tho!)

Code:
```	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;
}

}
my_arraystr[MAX][MAX + 1] = '\0';

}```

Thanks 4 input

The problem part is this part....

Code:
```my_arraystr[i][j] = my_array[i][j];
for(x='A'; x < 'K'; x++)
{
my_arraystr[i][j] = x;
}```
As all i get in every element of the string is the letter J.

When I run the program... 20 rows of 20 J's are displayed on screen.

What I want is that when the element of the array is a zero the letter 'A' is displayed, when it is 1 - the letter 'B' is displayed and so on up until when the element value is 9 - the letter 'J' is displayed! :S i hope thats clear

4. Hope the following code helps:
Code:
```   for (i=0; i<MAX; i++)
{
for (j=0; j<MAX; j++)
my_arraystr[i][j] = my_array[i][j]+'A';
my_arraystr[i][j] = '\0';
}

for (i=0; i<MAX; i++)
puts(my_arraystr[i]);```