0

I've been having this problem: when I try to print an array with 2 for loops nothing happens, blank screen. When I add a printf preceding the loop (anything like printf("1");) the loop printing shows in the execution. The code:

for(j=0;j<i;j++){
    printf("\n");
    for(k=0;k<i;k++){
        printf("%6d",*(polje+j*i+k));
    }
}

Not only does the program not print the loop, it says x.exe stopped working if I don't use another printf outside the loop.

2
  • Mostly it something to do with buffered output. Adding \n in printf solves the problem. There are other methods to force unbuffered stdout. Commented Apr 19, 2013 at 14:06
  • 1
    The chances are that the printing in the inner loop won't appear until you output a newline. Normally, you put the newline after the inner loop: for (int j = 0; j < i; j++) { for (int k = 0; k < i; k++) printf("%6d", polje[i*j+k]); putchar('\n'); }. Commented Apr 19, 2013 at 14:11

2 Answers 2

1

Try to call fflush(stdout); after your second printf.

Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

for(j=0;j<i;j++){
    printf("\n");
    for(k=0;k<i;k++){
        printf("%6d",(polje+j*i+k));
    }
}

I removed * in the second printf.. It was multiplying anything oh the right side

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.