I observed some behavior I can't explain myself when using printf to print a character via format-string. It seems that when the character is newline ('\n'), the printf ignores everything up to (including) '%c' and just prints the remaining part.
Here is a minimal example (user input to disable optimization):
#include <stdio.h>
int main(){
int c;
scanf("%d", &c); //read char by ascii id
printf("FOO%cBAR (id %i)\n", c,c);
return 0;
}
Entering 45 (the code for '-') results in output "FOO-BAR", but entering 13 ('\n') just prints "BAR". This happens both in gcc 6.3.1 and clang 3.9.1, on -Og and -O3 optimisation levels, on an linux.
This should not be related to output buffering if I'm not mistaken.
Is this behavior intended?