#include <stdio.h>
int main(void)
{
int i, b;
char a[10][10];
for (i = 0; i<10; i++)
{
for (b = 0; b<10; b++)
{
scanf("%c", &a[i][b]);
}
}
for (i = 0; i<10; i++)
{
for (b = 0; b<10; b++)
{
printf("%c", a[i][b]);
}
}
return 0;
}
Im new to c and im struggling with creating a 2d array with size 10x10.
I really dont know why but when i input, for example, this:
--IHH---I-
-H--------
----------
----H-----
----IH----
----H-----
----H-----
-H--------
---------I
-HI--H---I
I should be getting exactly the same, meaning:
--IHH---I-
-H--------
----------
----H-----
----IH----
----H-----
----H-----
-H--------
---------I
-HI--H---I
but it gives me this:
--IHH---I-
-H--------
----------
----H-----
----IH----
----H-----
----H-----
-H--------
---------I
-
But i discovered that instead of the code above i try this one:
#include <stdio.h>
int main(void)
{
int i, b;
char a[10][10];
for (i = 0; i<10; i++)
{
for (b = 0; b<11; b++)
{
scanf("%c", &a[i][b]);
}
}
for (i = 0; i<10; i++)
{
for (b = 0; b<11; b++)
{
printf("%c", a[i][b]);
}
printf("\n");
}
return 0;
}
Magically i get this output:
--IHH---I--
-H---------
-----------
----H------
----IH-----
----H------
----H------
-H---------
---------I-
-HI--H---I
As you can see I did not entered more "-" but every line except the final has another "-" at the end. I am confused.