0

See my code

char t[]= "{\n abcdeffgjejgjergnjkengkknkn \n";
printf("%s",t);

char t1[]= "{ abcdeffgjejgjergnjkengkknkn \n aaffdefa";
printf("%s",t1);

Actual Output:

{
{ abcdeffgjejgjergnjkengkknkn

Expected output:

{
 abcdeffgjejgjergnjkengkknkn 
{ abcdeffgjejgjergnjkengkknkn 
 aaffdefa

Can any one help me why string is not getting print after \n (LF)?

Compiler - arm-none-eabi

Library header - Newlib

IDE: MCUExpresso

1 Answer 1

0

By default stdout (where printf writes) is line buffered. That means the output buffer is flushed (actually written) either when it's full or when you print a newline.

That's why the second part of the output isn't printed, because it's not enough to fill the buffer and you have no newline to flush the buffer.

You can flush explicitly yourself by calling fflush:

printf(...);
fflush(stdout);
Sign up to request clarification or add additional context in comments.

2 Comments

but the same is working with other compiler (ARM by Keil)? Do you have any reference code for fflush?
@jtro Yes, print a trailing newline or explicitly call fflush.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.