c - Nested loop:inner loop is skipped once when executed -
int t,r,c; int matrix[100][100][100]; int i,j,k=0,l=0; int te,ck=0; scanf("%d",&t); for(te=0;te<t;te++) { printf("rc"); scanf("%d %d",&r, &c); for(i=0;i<r;i++) { for(j=0;j<c;j++) { printf("te= %d i= %d j= %d",te,i,j); fflush(stdin); matrix[te][i][j] = getchar(); } } }
sample o/p
abhi@ubuntu:~/desktop$ ./spoon.o 3 rc3 6 te= 0 i= 0 j= 0te= 0 i= 0 j= 1
the control directly asks value j=1 , j=0 skipped.why?
fflush(stdin)
not way clear input buffer. use:
void flushinputbuffer( void ) { int c; while( (c = fgetc( stdin )) != eof && c != '\n' ); }
Comments
Post a Comment