I have this Piece of COde that store a string in a 2-d char array.IN my code i am using a 2x6
2-D char array.On providing a 12digit string LIKE > "COMEHOMEARUN". It should store it as
C O M E H O
M E A R U N
but I am getting the output as
C O M E H M
M E A R U N ...i.e the value at [0]6] automatically gets the value of [1][0].
here's the code
#include<stdio.h>
#include<conio.h>
void main()
{
char string[20];
char aray[1][5];
int i,j,k=0;
gets(string);
//storing the individual characters in the string in the form of 2x6 char array
for(i=0;i<=1;i++)
{
for(j=0;j<=5;j++)
{
aray[i][j]=string[k];
k++;
}
}
//displaying the array Generated
for(i=0;i<=1;i++)
{
for(j=0;j<=5;j++)
{
printf("%c ", aray[i][j]);
}
printf("\n");
}
getch();
}
Does anybody know where I am going wrong?