-1

I am trying to debug using printf. I have inserted it between for loops, but I do not receive the output of it. I am certain that the algorithm is continuing after it and arriving to the end, it's like the reader is ignoring it.

Here's the code :

for (i = 0; i < lower; ++i) {
    buf3[i] = (buf[i] + buf2[i] )/2;
    printf("\n %d",buf3[i]);
}
printf("hiiiiiiiiiiiiiiiiiiii %d",i);

for (i; i < upper; ++i) {
    if (upper == num2) {
        buf3[i] += buf2[i]/2;
        printf("\n %d",buf3[i]);

    }
    else {
        buf3[i] += buf[i]/2;
        printf("\n %d",buf3[i]);

    }
}


printf("\n %d",upper);

The "hiiiii..." message is the one not being seen on the screen. (I tried replacing it by many other messages such as int or anything else, but in vain. I also tried to put another printf right above the first for loop, again it returned nothing).

Please note that upper and lower aren't huge numbers.

Thanks in advance.

2 Answers2

3

The printf in question does not print a newline, so the output is buffered until a later printf prints a newline.

Add the newline, and you should see the output:

printf("hiiiiiiiiiiiiiiiiiiii %d\n",i);
dbush
  • 162,826
  • 18
  • 167
  • 209
0

Try adding \n after %d.
Also i is not initialised in the second loop

cp2014
  • 21
  • 2