1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
| #include <stdio.h>
#include <string.h>
#ifdef WINDOWS
#include <conio.h>
#else
#include <termios.h>
#include <unistd.h>
int getchar(void);
#endif
void main(void)
{
int cCaractere='0';
do
{
printf("Press any keys - CTRL-D will terminate this program\n"); // Pour arreter le programme j'utilise CTRL-D
cCaractere=getchar(); // La fonction getch lit les caractères saisit au clavier
printf("%d %o %x\n",cCaractere,cCaractere,cCaractere); // J'affiche les caractere en valeur décimal, octal et hexadécimal
while(cCaractere !='4');// Le programme s'arrète quand cCaractere est égal à CTRL-D
}
#ifdef LINUX
int getch(void)
{
struct termios oldt, newt;
int cCaractere;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
cCaractere = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
return cCaractere;
}
#endif |
Partager