LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 08-21-2011, 12:07 PM   #1
RLN37
LQ Newbie
 
Registered: Aug 2011
Posts: 4

Rep: Reputation: Disabled
getch function - where to get it


I think I understand that getch() is a function in conio.h.
And that conio.h is not included with gcc for Ubuntu.
But I still need getch(). Can I use a copy of the conio.h file
that is said to be available on a Windows system? If not, how
can I get hold of a useable version of conio.h?

Thanks for the help.

Baseball Bob
 
Old 08-21-2011, 01:10 PM   #2
tronayne
Senior Member
 
Registered: Oct 2003
Location: Northeastern Michigan, where Carhartt is a Designer Label
Distribution: Slackware 32- & 64-bit Stable
Posts: 3,541

Rep: Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065Reputation: 1065
From the getch() manual page:
Code:
NAME
       getch, wgetch, mvgetch, mvwgetch, ungetch, has_key - get (or push back) characters
       from curses terminal keyboard

SYNOPSIS
       #include <curses.h>

       int getch(void);
       int wgetch(WINDOW *win);
       int mvgetch(int y, int x);
       int mvwgetch(WINDOW *win, int y, int x);
       int ungetch(int ch);
       int has_key(int ch);
You will find, in The C Programming Language, both the fist and second editions, a demonstration of a getch() function (on page 79 of, yup, both editions). Note that you would not actually use this function in practice, it's for illustration purposes only.
Code:
#include <stdio.h>              /* needed for printf() */

#define BUFSIZE 100

char    buf [BUFSIZE];          /* buffer for ungetch() */
int     bufptr = 0;             /* next free position in buf */

int     getch (void)            /* get a (possibly pushed back) character */
{
        return (bufptr > 0) ? buf [--bufptr] : getchar ();
}

void    ungetch (int c)         /* push character back on input                 */
{
        if (bufptr >= BUFSIZE)
                printf ("ungetch: too many characters\n");
        else
                buf [bufptr++] = c;
        return;
}
Hope this helps some.

Last edited by tronayne; 08-23-2011 at 11:29 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
getch substitute narendra.pant Programming 1 02-24-2007 07:11 AM
getch() strycnine Programming 6 01-30-2007 01:47 PM
Where is getch()....... rajsun Programming 2 03-28-2005 11:40 AM
getch function prasad514 Programming 6 01-03-2005 11:48 AM
Help with getch... darkarcon2015 Programming 4 09-12-2004 08:48 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 02:24 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration