我現在在Ubuntu上工作。當我使用gcc編譯我的C程序時,它給出錯誤conio.h
不存在。 我想用clrscr()
和getch()
函數。 可以請你告訴我這個頭文件在Linux中的替代品。c for linux中getchar和clrscr()的子化程序
回答
getch()
函數可以在curses.h
(library「curses」)中找到。同一個庫提供清除屏幕的功能。看看這些鏈接:
我相信curses'getch()'函數只有在調用'initscr()'後才能使用,它控制了(文本)屏幕。 – 2012-08-06 07:20:45
顯然,你沒有嘗試使用Google。
沒有直接的選擇。
本博客文章:爲您提供替代品getch()
和getche()
或者您可以使用的libncurses做你想要的:http://tech.dir.groups.yahoo.com/group/linux/message/29221
我正在嘗試curses.h,並且它也未在我的ubantu o.s – 2012-08-06 07:27:31
上找到您是否嘗試將其定位到存儲庫中?如果您不知道如何操作,請嘗試askubuntu.com。 – Axel 2012-08-06 07:51:39
curses.h是CONIO.H替代。 安裝build-essentials並安裝libncurses5-dev。
然後你可以使用該功能。 [http://ubuntuforums.org/showthread.php?t=880601][1]
system("clear");
可以在linux下代替的clrscr();
# include <curses.h>
int erase(void);
int werase(WINDOW *win);
int clear(void);
int wclear(WINDOW *win);
int clrtobot(void);
int wclrtobot(WINDOW *win);
int clrtoeol(void);
int wclrtoeol(WINDOW *win);
DESCRIPTION
The erase and werase routines copy blanks to every position in
the window, clearing the screen.
我猜這個問題是使用因爲這意味着對基本C語言功能的理解不夠和/或OP只是將代碼複製/粘貼到編輯器/ IDE中,所以反覆下調。
類似的,只是你的代碼中使用system("exit");
:
#include<stdlib.h>
main()
{
system("clear"); //clears the screen
}
檢查人的頁面顯示:
SYSTEM(3) Linux Programmer's Manual SYSTEM(3)
NAME
system - execute a shell command
SYNOPSIS
#include <stdlib.h>
int system(const char *command);
DESCRIPTION
system() executes a command specified in command by calling /bin/sh -c
command, and returns after the command has been completed.
During execution of the command, SIGCHLD will be blocked, and SIGINT
and SIGQUIT will be ignored.
它也可能是這個問題是可能重複的情況下以下:
- How to implement getch() function of C in Linux?
- Why can't I find <conio.h> on Linux?
- GNU/Linux replacements for Turbo C functions `clrscr` and `cprintf`
- Function clrscr in C and C++
- "UNDEFINED REFRENCE TO clrscr();"
- Substitute for getch(), gotoxy(), delay(), clrscr()
- What is Equivalent to getch() & getche() in Linux?
最後,來看看更多細節和例子如下:
我與一些代碼修補左右;我安裝了ncurses之後,我插入了這些代碼:
#include <stdio.h>
#include <ncurses.h>
main()
{
system ("clear");
getchar();
}
還有一種方法可以通過C代碼來代替系統調用。
void clrscr(void) {
fprintf(stdout, "\033[2J\033[0;0f");
fflush(stdout);
}
我發現它很久以前,我成功地檢查了它在raspbian上。
而且也:
void gotoxy(int x, int y) {
printf("%c[%d;%df",0x1B, y, x);
}
我希望它可以幫助你。
問候。
- 1. for循環和getchar()在C
- 2. C程序第一的getchar()
- 3. 用於Turbo C函數`clrscr`和`cprintf`的GNU/Linux替換
- 4. 模塊化編程和編譯linux中的C程序
- 5. For循環和getchar/putchar在C中的使用
- 6. Putchar和Getchar in C
- 7. 尋找的getchar()程序
- 8. C getchar()hang子手遊戲
- 9. getchar()並計算C中的句子和單詞
- 10. 發送來自Linux中的C/C++程序的電子郵件
- 11. 的getchar,在C
- 12. C在Linux中的C++圖形程序
- 13. 「未定義的clrscr();」
- 14. 用於Linux和/或MonoDevelop的C#代碼格式化程序
- 15. C代碼,scanf和getchar
- 16. (c = getchar())!= EOF在C#中?
- 17. for for語句中使用getchar()不能正常工作
- 18. C程序設計:的getchar存儲爲字符數組
- 19. 如何使用getchar運行程序?
- 20. getchar()和stdin
- 21. C getchar()誤解
- 22. C getchar錯誤
- 23. 在C或C++和Linux中的屏幕捕獲程序
- 24. Strcmp和getchar
- 25. MongoDB for C#和iPhone應用程序
- 26. 在Windows和Linux上運行C++程序
- 27. 尋求和在Linux C++應用程序
- 28. C - getchar和動態創建的數組
- 29. C程序設計有關的getchar((初級幫助))的putchar()
- 30. 如何從windows for linux移植C#應用程序?
查看[ncurses](http://en.wikipedia.org/wiki/Ncurses)庫。 – 2012-08-06 07:17:31
[GNU/Linux替代Turbo C函數\''clrscr \'和\'cprintf \']的可能重複(http://stackoverflow.com/questions/7079943/gnu-linux-replacements-for-turbo-c-函數-clrscr-and-cprintf) – DevSolar 2015-10-23 08:22:36