clrscr()関数の使い方はどうですか?
clrscr()関数は、コンソール画面上の全ての文字とカーソル位置を消去して、新しい内容を表示するために使用されます。しかし、clrscr()関数はC言語標準ライブラリに存在せず、特定のコンパイラやオペレーティングシステムが提供する拡張関数です。
以下是一些常用的クリアスクリーン関数の例:
- システムをクリアします。
#include <stdio.h>
#include <stdlib.h>
#include <Windows.h>
int main() {
printf("This is some content on the screen.\n");
Sleep(2000); // 等待2秒
system("cls"); // 清除屏幕内容
printf("Screen is now cleared.\n");
return 0;
}
- システム(「クリア」)
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("This is some content on the screen.\n");
sleep(2); // 等待2秒
system("clear"); // 清除屏幕内容
printf("Screen is now cleared.\n");
return 0;
}
system()関数はシステムコマンドを実行する可能性があるため、セキュリティリスクを招く可能性があります。そのため、使用する際には注意が必要です。また、画面の内容を削除する具体的な方法は、コンパイラや操作システム、ターミナルの種類によって異なる可能性があります。