Originally Posted by
Poincare
I know that with only C, you cannot interface with the keyboard or monitor but you can with assembly. I was wondering if just to recieve input from the say the keyboard (not parse it or anything, just recieve)would 300+ lines of code or was it easier than that? If it is a reasonable amount, then can someone post the code or direct me toward a link?
You can use C, and you should use C. You just can't use *PURE as the driven snow*, standard C.
Just find a compiler that includes (or can be arm-twisted), into using kbhit(). I use legacy Borland Turbo C/C++ ver. 1.01 for this, (using just the C compiler, not the C++ compiler), but a library like Ncurses may handle it, as well as other compilers.
Code:
/*
kbhit Checks for currently-available keystrokes.
Syntax:
int kbhit(void);
Prototype in:
conio.h
Remarks:
kbhit checks to see if a keystroke is currently available.
Any available keystrokes can be retrieved with getch or getche.
Return Value:
If a keystroke is available, kbhit returns a nonzero integer; if not, it
returns 0.
Portability:
kbhit is unique to DOS. (Works fine in Windows XP, however)
See Also:
getch getche
Example:
*/
#include <conio.h>
#include <stdio.h>
int main(void)
{
int key1;
cprintf("Press any key to continue:");
while (!kbhit()) /* do nothing */ ;
//getchar() (below) is standard C. getch() is part of the
//non-standard (but useful), conio.h
key1 = getch(); //get a letter, w/o an enter key being needed
//print the int that was pressed, as a letter
printf("\r\nA key was pressed: %c", key1);
//print the same int as it's ascii int value
printf("\r\nA key was pressed: %d", key1);
printf("\n\t\t\t Press Enter When Ready ");
key1 = getchar(); //pause the screen from closing
return 0;
}