taking char input in two dimensional array

36 views Asked by At

i was trying to solve tic tac toe problem. i take sample input like this (no white space) :

X0X
.0.
.X.

i declare a two dimensional array of char char a[3][3] i run loops to take input but it don't take input correctly

Here is what i try :

#include<stdio.h>
#include<string.h>
int main() {
    int i,j;
    char a[3][3];
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            scanf("%c",&a[i][j]);
        }
    }
    for(int i=0;i<3;i++){
        for(j=0;j<3;j++){
            printf("%c",a[i][j]);
        }
        printf("\n");
    }
}

all i get return was

X0X

.0
.
.

for the sample above. i solved the problem in c++ without any bugs but in c its not working. i also try the above above code in codeforce to check if i was taking input correctly with gcc c11 compiler and found same issue. How can i solve this?

0

There are 0 answers