Why is my for loop not taking 9 inputs?

c, for-loop, loops

Solution

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.

Problem

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?

Original source

Related problems