is there a DOS/UNIX/ANSI C compatible getch() like function?

This is a discussion on is there a DOS/UNIX/ANSI C compatible getch() like function? within the C++ Programming forums, part of the General Programming Boards category; I am trying to make a fully compatible getch() like function. In Borland Turbo C++ and many other dos compilers, ...

  1. #1
    Unreg
    Guest

    Unhappy is there a DOS/UNIX/ANSI C compatible getch() like function?

    I am trying to make a fully compatible getch() like function.
    In Borland Turbo C++ and many other dos compilers, it is only dos compatible.
    Why can't they make it more compatible?
    However, it's entirely different between conio.h and curses.h.
    Not even kbhit() is compatible with both unix and dos.
    Does anyone know if such function exists?
    If not, I have a piece of asm routine I made that is similar to getch().
    Can someone help error check the asm code just in case I messed up somewhere?
    I just don't know how to implement this into C.
    Can anyone refer me to a very compatible getch() function or put the asm code into a union regs or something?
    I've never done this before.
    By the way, this is not my school assignment.
    Maybe this is homework to some people but to me it is just personal curiousity (They don't even have CS/CIS courses in my school).
    Thanks.
    Here is the code:
    Code:
    ;asm
    LOOP: MOV AH, 01 ; triggers when key press is made
          INT 16H ; type
          JZ LOOP ; jump to "LOOP" if false
          ; otherwise:
          MOV AH, 0 ; retrieve value
          INT 16H ; type
          ; one problem:
          ;  in C programming, a value is returned from a function.
          ;  in this case, AL holds the ASCII value and AH holds the scan key value.
          ;  how do I return the value from AL or AH?
          ;  do I do something like this: "return AL;" at the end of function?

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    What about getchar( )

  3. #3
    Unreg
    Guest
    I want it to have a "getch() like" characterisitic.
    This means no enter key involved.
    is portable code really hard to find?

  4. #4
    Just a Member ammar's Avatar
    Join Date
    Jun 2002
    Posts
    953
    I'm not sure, but I think I've heard about a function called kbhit(), maybe you would like to check it out!

  5. #5
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by ammar
    I'm not sure, but I think I've heard about a function called kbhit(), maybe you would like to check it out!
    Both getch() and kbhit() are conio.h functions.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  6. #6
    Unreg
    Guest
    Originally posted by vVv
    FAQ

    No, it's not fully portably possible.
    not even that asm code is DOS<->UNIX portable?
    can someone help me put that asm code into a union regs?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  2. <Gulp>
    By kryptkat in forum Windows Programming
    Replies: 7
    Last Post: 01-14-2006, 12:03 PM
  3. Problem with Visual C++ Object-Oriented Programming Book.
    By GameGenie in forum C++ Programming
    Replies: 9
    Last Post: 08-29-2005, 11:21 PM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 06:05 PM
  5. c++ linking problem for x11
    By kron in forum Linux Programming
    Replies: 1
    Last Post: 11-19-2004, 09:18 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21