2983 (fingeruebung)

this is the windows-thang for a keypress-read without enter. output char and ascii-value. loop terminated by ‘#’.

//offensichtlich ein windowsding
#include<stdio.h>//standardinout
//windows for kbhit and getchar
#include<conio.h>
//for sleep
#include<windows.h>
//linux
//#include <termios.h>
//#include <string.h>
int main() {

int countdown;
char ch;
int wert;
char b;
do {
	while(countdown++ <= 1000)
	{  
    		if(b=kbhit())            
        	break;             
    		Sleep(1);   
	}
	ch = getch();
	wert = ch;
	if (b != 0)        
    		{ printf("key %c ascii %d\n", ch, wert);}
} while (ch != '#');
printf ("programmende\n");
return 0;
}

2960 (c specifiers)

item format comment
%d(%i) signed int,(short,long) decimal
%u unsigned int positive decimal
%x,%X unsigned int hexadecimal
%o unsigned int octal
%c char single character
%s array of char string(sequence of chacters)
%f signed float,double floating point
%e,%E float,double floating point(exponential)
%g,%G float,double {([%f or %e])}
%p ? pointer address stored in pointer

2704 (BASIC GET in c)

The following c-program reads a single keystroke without enter. Output is the key and its ascii-value. The keys are read in a loop that is interrupted by the #-sign. Note that this is not trivial.

#include <stdio.h>
#include <termios.h>
#include <string.h>

int kbhit(void);
int kbhit(void) {
	struct termios term, oterm;
	int fd = 0;
	int c = 0;
	tcgetattr(fd, &oterm);
	memcpy(&term, &oterm, sizeof(term));
	term.c_lflag = term.c_lflag & (!ICANON);
	term.c_cc[VMIN] = 0;
	term.c_cc[VTIME] = 1;
	tcsetattr(fd, TCSANOW, &term);
	c = getchar();
	tcsetattr(fd, TCSANOW, &oterm);
	if (c != -1)
	ungetc(c, stdin);
	return ((c != -1) ? 1 : 0);
}

int getch();
int getch()
{
	static int ch = -1, fd = 0;
	struct termios neu, alt;
	fd = fileno(stdin);
	tcgetattr(fd, &alt);
	neu = alt;
	neu.c_lflag &= ~(ICANON|ECHO);
	tcsetattr(fd, TCSANOW, &neu);
	ch = getchar();
	tcsetattr(fd, TCSANOW, &alt);
	return ch;
}

int rechne(char v);
int rechne(char v) {
	int vback;
	vback = v;
	return vback;
}

int main() {
	char c;
	int interr;
	interr = 1;
	do {
		do {
	   		c = getch();
	   		if (c == '#') {
				interr = 0;
				break;
			}
	   	int wert;
	   	wert = rechne(c);
	   	printf("char '%c' key '%d'\n", c, wert);
	 	}
		while(kbhit());
	}
	while(interr);
printf("programmende\n");
return 0;
}