My code only takes 5 values as input.? What am i doing wrong?
#include<stdio.h>
#include<stdlib.h>
int main()
{
char arr[3][3];
int i,j,n;
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
scanf("%c",&arr[i][j]);
}
}
return 0;
}
How should i correct it?
Change
scanf("%c",&arr[i][j]);
to
scanf(" %c",&arr[i][j]);.
Notice the space given before specifier to consume \n
left in stdin buffer when you pressed enter.
Each \n
is working as input taking your space from input space.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With