1

Today I wrote a code in c with putchar so I can translate it to assembly, but the last putchar I call doesnt print, if I add a newline after it works.

else if(R5 == 0x2B) // PLUS
    {

    .....

      if(R8 >= 10 || R8 == 0)
      {
        R5 = 0;
zhnr: if(R8 >= 10)
        {
          R8 = R8 - 10;
          R5++;
          goto zhnr;
        }
        putchar('0'+ R5);
      }
      putchar('0'+ R8);   // THIS IS THE LAST PUTCHAR WHICH DOESNT PRINT
      // IF I ADD HERE: putchar('\n'); It works
    }
zwerg4
  • 320
  • 3
  • 5
  • 12
  • Why don't you want to print a newline after the last character? – Jongware Apr 14 '18 at 10:25
  • 1
    Possible duplicate of [getch and putchar not working without return](https://stackoverflow.com/questions/10256477/getch-and-putchar-not-working-without-return) (line buffering issue) – hnefatl Apr 14 '18 at 10:26

1 Answers1

3

stdout is typically buffered and only flushed when you output new lines.
You can either flush it manually using fflush(stdout); or disable buffering using setbuf(stdout, NULL);

Janne Husberg
  • 294
  • 1
  • 9