LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1367|回复: 12

在C下有哪个是清屏的函数?

[复制链接]
发表于 2003-9-28 20:40:49 | 显示全部楼层 |阅读模式
在C下有哪个是清屏的函数?
发表于 2003-9-28 21:03:32 | 显示全部楼层
1.

  1. void clear_screen()
  2. {
  3. #if defined(WIN_32)
  4. system("cls")
  5. #endif
  6. #if defined(LINUX)
  7. system("clear")
  8. #endif
  9. }
复制代码

This is a system call under linux, calling system command "clear" to clear terminal screen.
It is the simplest way.

2.

  1. /* clearscreen.c  clear terminal screen */
  2. #include <stdio.h>
  3. #include <ncurses.h>

  4. main()
  5. {
  6. initscr();
  7. clear();
  8. refresh();
  9. endwin();

  10. printf("Hello, world!");

  11. }

  12. compile with:
  13. # cc -o clearscreen clearscreen.c -lncurses
复制代码

It is a more effective way under linux, looks like more standard.

3.

  1. void cls()
  2. {
  3. for(i=0; i<=25; ++i)
  4. printf("\n");

  5. return(0)
  6. }
复制代码

Oh, this is more portable way under either linux or win32, but not the best.
 楼主| 发表于 2003-9-28 21:10:49 | 显示全部楼层
俺太菜,看不懂。
 楼主| 发表于 2003-9-28 21:12:01 | 显示全部楼层
我是在Linux下运行程序的。
发表于 2003-9-28 21:13:09 | 显示全部楼层
哪里看不懂了?!
照第2个示例写一个,远行一下就明白了。
发表于 2003-9-28 21:46:19 | 显示全部楼层
vt100下可以用:
printf("\033[H\033[J");
发表于 2003-9-29 00:16:32 | 显示全部楼层
void cls()
{
for(i=0; i<=25; ++i)
printf("\n");

return(0)
}

沒話說
发表于 2003-9-29 01:37:14 | 显示全部楼层
哈,网上找的,没测试。

  1. void cls()
  2. {
  3.     int i;
  4.     for(i = 0; i <= 25; ++i)
  5.     printf("\n");
  6. }
复制代码
发表于 2003-9-29 08:34:57 | 显示全部楼层
打出25 个回车,多好啊,不用调用函数。这方法我以前还告诉过朋友呢。:)
发表于 2003-9-29 16:53:22 | 显示全部楼层
我常常用43/60行的
或許打出60 个回车好些 :p
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表