I am getting weird results when I try to take input of a 2D char array for some reason. I have always taken integer 2D arrays in the past this way but somehow this method doesn't work for char arrays.
#include <stdio.h>
int main()
{
int i,j,n;
scanf("%d",&n);
char a[n][n];
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
scanf("%c",&a[i][j]);
}
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%c",a[i][j]);
}
return 0;
}
Excepted Input:
3
a b c
d e f
g h i
Expected Output:
a b c
d e f
g h i
What happens:
3
a b c
d e f
(Input abruptly stops)
Output:
a b c
d