The escape sequences appearing the string of writef/2 are thus already interpreted when writef/2 sees them, and they are those used by the C-library (except for \?). In particular, at that level, \% is an unknown escape sequence and leads to an error:
ERROR: Syntax error: Unknown character escape in quoted atom or string: `\%'
To drill through the Prolog lexer, one has to escape the backslash. For example, for the newline:
S = ">\\n<",
A = '>\\n<',
C = [62, 92, 110, 60].
..... And also
This is also mentioned at
although in the context of character escapes in atoms, not strings.