2012-08-06 13 views
1

我現在在Ubuntu上工作。當我使用gcc編譯我的C程序時,它給出錯誤conio.h不存在。 我想用clrscr()getch()函數。 可以請你告訴我這個頭文件在Linux中的替代品。c for linux中getchar和clrscr()的子化程序

+3

查看[ncurses](http://en.wikipedia.org/wiki/Ncurses)庫。 – 2012-08-06 07:17:31

+0

[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

回答

0

顯然,你沒有嘗試使用Google。

沒有直接的選擇。

本博客文章:​​爲您提供替代品getch()getche()

或者您可以使用的libncurses做你想要的:http://tech.dir.groups.yahoo.com/group/linux/message/29221

+0

我正在嘗試curses.h,並且它也未在我的ubantu o.s – 2012-08-06 07:27:31

+0

上找到您是否嘗試將其定位到存儲庫中?如果您不知道如何操作,請嘗試askubuntu.com。 – Axel 2012-08-06 07:51:39

0

curses.h是CONIO.H替代。 安裝build-essentials並安裝libncurses5-dev。

然後你可以使用該功能。 [http://ubuntuforums.org/showthread.php?t=880601][1]

1

system("clear");可以在linux下代替clrscr();

1
# 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. 

它也可能是這個問題是可能重複的情況下以下:

最後,來看看更多細節和例子如下:

0

我與一些代碼修補左右;我安裝了ncurses之後,我插入了這些代碼:

#include <stdio.h> 
#include <ncurses.h> 

main() 
{ 

system ("clear"); 
getchar(); 

} 
0

還有一種方法可以通過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); 
} 

我希望它可以幫助你。

問候。