私は\b
エスケープシーケンスの機能を理解しようとしている次のプログラムを持っています。 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;
}
出力:期待Hello\b\b
プリントHell
が、2つの\b
文字を含むstrlen()
戻る7として
$ ./a.out
Hel 7
Hel 7
$
。次のように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
と他のエスケープシーケンスはコンパイル時または実行時に解決されますか?
実際、これらを「制御文字」といいます。 「エスケープ」とは、後続の文字の意味を変更するために使用される特定の制御文字を指します。 –
@HotLicks:良い点、ありがとう。 – thiton
(他に良い投稿 - 私はそれを+1しました) –