1

This is my code:

 #include<stdio.h>
    int main() 
    {

        char a[10][10];

        int i,n,m,j;

        n=2;
        m=2;


        for(i=0;i<n;i++)
            for(j=0;j<m;j++)
            {
                scanf("%c",&a[i][j]);
            }

        for(i=0;i<n;i++)
        {
            for(j=0;j<m;j++)
            {
                printf("%c",a[i][j]);
            }
        }

    }

Output:

a b c d

a b

Process returned 0 (0x0) execution time : 3.965 s Press any key to continue.

Lalit Verma
  • 782
  • 10
  • 25

1 Answers1

2

Because they are storing and two of them is the space. That's why you don't see them.

Try this and you will understand

printf("[%c]",a[i][j]);

To solve the issue you can do this

scanf(" %c",&a[i][j]);

This consumes the white space character between the two character input.

From standard:- 7.21.6.2

Input white-space characters (as specified by the isspace function) are skipped, unless the specification includes a [, c, or n specifier

and this

A directive composed of white-space character(s) is executed by reading input up to the first non-white-space character (which remains unread), or until no more characters can be read. The directive never fails.

user2736738
  • 30,591
  • 5
  • 42
  • 56