未分類

c言語 ターミナル上で出力した文字列の表示を初期化する

投稿日:2020年11月27日 更新日:

エスケープシーケンス \033[2J と\033[u を使う。

#include <unistd.h>
#include <stdio.h>

int main()
{
int i = 0;
while (true)
{
i++;
printf("\033[2J\033[ui = %d\n",i);
usleep(1000);
}

return 0;
}

結果

i = 1117

のような出力が出続ける。

-未分類
-

執筆者:


comment

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

関連記事

no image

c++ で文字列を「区切り文字」を使って分ける方法

string の find を使って、区切り文字の場所を取得し、その位置で区切る。 例 #include <iostream> #include <string> using namesp …

no image

tex で行の色を1行ごとに交互につける

色を1行ごとに交互につけるには、\xcolor パッケージを使った上で、\rowcolors コマンドを使って色を指定する。 例 \usepackage[table]{xcolor} \begin{d …

no image

python3 で文字列を区切り文字を指定してリストに変換する方法

split メソッドを使う。 例 str1 = ‘this, is, a, pen’ str2 = str1.split(‘,’) print(str2) 結果 [‘this’, ‘ is’, ‘ a …

no image

tex で脚注を表示する方法

\footnote を使う。 例 \footnote{this is a footnote.} 結果

no image

tex で打ち消し線を入力する方法

次のように入力すればよい。打ち消し線は、英語で strikethrough と呼ぶ。 例 \usepackage[normalem]{ulem} \begin{document} Good \sout …