У меня есть следующая программа, в которой я пытаюсь понять функционирование escape-последовательности \b
.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int disp(char *a)
{
return printf("%s", a);
}
int main(void)
{
char *s = "Hello\b\b";
printf(" %d\n", disp(s));
printf("%s %d\n", s, strlen(s));
return 0;
}
Выход:
$ ./a.out
Hel 7
Hel 7
$
Как и ожидалось Hello\b\b
печатает Hell
, но strlen()
возвращает 7, включая два символа \b
.
Согласно C99 5.2.2 \b
определяется следующим образом:
\b (backspace) Moves the active position to the
previous position on the current line. If the
active position is at the initial position of
a line, the behavior of the display device is
unspecified.
Как \b
интерпретируется в функциях, связанных со строками, таких как strlen()
? \b
и другие escape-последовательности разрешены во время компиляции или во время выполнения?