I initialize array with characters a2[3][4] from a1 array and I want to insert a NULL ‘\0’ to the items a2[i][4] in the array and then when I Print the array I don’t get all characters printed and I don’t know why, and when I don’t store ‘\0’ it prints ok.
Code:
#include <stdio.h>
int main()
{
int a1[3][3];
char a2[3][4];
char a3[10]= {'*','#','@','%','&','!','^','>','<',':'};
int i,j;
a1[0][0]=6; /* storing values in the array a1 */
a1[0][1]=3;
a1[0][2]=0;
a1[1][0]=4;
a1[1][1]=9;
a1[1][2]=2;
a1[2][0]=2;
a1[2][1]=6;
a1[2][2]=7;
for (i=0;i<=2;i++)
{
for (j=0;j<=2;j++)
{
a2[i][j]= a3[a1[i][j]]; /* storing characters in the array a2 */
if (j = 2)
a2[i][j+1]='\0'; /* storing null in a2[i][3] */
/* ****** the problem in the above line */
}
}
printf("\n");
for (i=0;i<=2;i++)
{
for (j=0;j<=3;j++)
{
printf("%c",a2[i][j]); /* printing character from array a2 */
}
}
return(0);
}