I’m trying this code for entering values into multidimensional char array in C.
The code:
char s[2][2];
char TRUE = '1';
for (i =0; i < 2; i++)
{
for (j = 0; j < 2; j++)
{
scanf("%c\n", &s[i][j]);
printf("%c\n", (char)s[i][j]);
printf("###\n");
if (s[i][j] == TRUE)
printf("Char are equal\n");
else
printf("Not\n");
}
}
The problem is that for that first scanf(), i’m getting Null value.
This code works good only from the second scanf().
The code purpose is to enter ‘1’ and ‘0’ values and then compare if the input is equal to TRUE (‘1’).
There are many problems with
scanf()by default. You should call it:or if
fflush()isn’t available on your operating system that would be help:Hope that helped 🙂