Mailinglist Archive: opensuse-programming (68 mails)

< Previous Next >
Re: [suse-programming-e] C++ compile problem. error in function
  • From: Jerry Feldman <gaf@xxxxxxx>
  • Date: Wed, 14 Jan 2004 09:07:58 -0500
  • Message-id: <20040114090758.41a3f715@xxxxxxxxxxx>
Hash: SHA1

On Tue, 13 Jan 2004 20:33:38 +0000
Ged <ged.suse@xxxxxxxxxxxx> wrote:

> It seems to stick on 11. It won't always let me input item number 12.
> The items i'm trying to enter are as follows.
I tested your code with the changes I listed below so it works on SuSE
Linux. I was able to enter all the stock items in your list and list all
13 out.

Here are the changes I made to your program (only to replace the Windows
specific issues with Linux compatible code).

#include <cerrno>
/***************** include unistd.h and termios.h for getch() ***/
#include <unistd.h>
#include <termios.h>
// Conio is a WINDOWS specific header.
// #include <conio.h> //for getch()

2. void cls(void) { system("clear"); } // so this works on Unix/Linux
* Simulate the Windows conio function getch
char getch()
int rv;
char ch;
int fd = 0; // force to stdin
struct termios oldflags, newflags;
/*********** Reset the terminal to accept unbuffered input ***/
/* get the current oldflags */
tcgetattr(fd, &oldflags);
/* make a copy of the flags so we can easily restore them */
newflags = oldflags;
/* set raw input */
newflags.c_cflag |= (CLOCAL | CREAD);
newflags.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG);

/* set the newflags */
tcsetattr(fd, TCSANOW, &newflags);
rv = read(fd, &ch, 1);
/* restore the oldflags -- This is important otherwise
* your terminal will no longer echo characters
tcflush(fd, TCIFLUSH);
tcsetattr(fd, TCSANOW, &oldflags);
return ch;

- --
Jerry Feldman <gaf@xxxxxxx>
Boston Linux and Unix user group PGP key id:C5061EA9
PGP Key fingerprint:053C 73EC 3AC1 5C44 3E14 9245 FB00 3ED5 C506 1EA9
Version: GnuPG v1.2.2-rc1-SuSE (GNU/Linux)


< Previous Next >