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

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -