[comp.os.msdos.programmer] help need in C

tmurphy%peruvian.utah.edu@cs.utah.edu (Thomas Murphy) (04/14/91)

In article <7339@munnari.oz.au> ksiew@ecr.mu.oz.au (Kok-Hsien SIEW) writes:
>
> On Turbo Pascal 5.5 I could write the following code:
> 
>  repeat
>    do_calculations;
>  until keypressed;
>  inchar:=readkey;
>  writeln('The key you pressed is ',inchar);
> 

In Turbo C I would do it like this:
  
   #include <bios.h>
main()
{
 int key;
 
  while(bioskey(1) == 0){
    do_calculations
  }
  key = bioskey(0);
  printf("the key you pressed was %d \n" key);
}

pretty short and simple eh?

murph

tmurphy@peruvian.cs.utah.edu

joe@proto.com (Joe Huffman) (04/15/91)

ksiew@ecr.mu.oz.au (Kok-Hsien SIEW) writes:


> On Turbo Pascal 5.5 I could write the following code:
> 
>  repeat
>    do_calculations;
>  until keypressed;
>  inchar:=readkey;
>  writeln('The key you pressed is ',inchar);
> 
>  But how do I do this in Turbo C and Unix C?

Under Zortech C (both the MSDOS and SCO UNIX version) this can be written
as:

#include <stdio.h>
#include <conio.h>

void do_calculations(void)
{
	printf("Hello world... 2 + 2 = %d\n", 2 + 2);
}

int main(int argc, char *argv[])
{
	int inchar;

	do
        {
	    do_calculations();
        } while(!kbhit());

	inchar = getch();
	printf("The key you pressed is '%c' (0x%x)\n", inchar, inchar);

	return 0;
}

-- 
joe@proto.com