subsititue of getchar and clrscr() in c for linux
Solution 1
The getch()
function can be found in curses.h
(library "curses"). The same library offers functions to clear the screen. Check out these links:
http://linux.die.net/man/3/getch
http://linux.die.net/man/3/erase
Solution 2
# 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.
I'm guessing this question was repeatedly downvoted because it implies a poor understanding of basic C language features and/or that OP is simply copying/pasting code into editor/IDE.
Similarly, just use system("exit");
within your code:
#include<stdlib.h>
main()
{
system("clear"); //clears the screen
}
Checking the man-pages shows:
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.
It could also be the case that this question is a possible duplicate of the following:
- 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?
Finally, take a look at the following for more details and examples:
- http://tldp.org/HOWTO/NCURSES-Programming-HOWTO/scanw.html#GETCHCLASS
- http://ubuntuforums.org/showthread.php?t=549023
Solution 3
system("clear");
can be used in linux instead of clrscr();
Related videos on Youtube
Daarks Solutions
Updated on September 15, 2022Comments
-
Daarks Solutions over 1 year
I am working on Ubuntu these days. When I compiled my C program using gcc, it is giving the error
conio.h
doesn't exists. I want to useclrscr()
andgetch()
function. Can you please tell me the substitute of this header file in linux.-
Some programmer dude over 11 yearsCheck out the ncurses library.
-
-
Keith Thompson over 11 yearsI believe the curses
getch()
function can be used only after callinginitscr()
, which takes control of the (text) screen. -
Daarks Solutions over 11 yearsI am trying for curses.h and it too is not found on my ubantu o.s
-
Axel over 11 yearsHave you tried locating it in the repositories? If you don't know how to do that, try askubuntu.com.