- /*
- Name: SPECHAR
- Version: 0.2
- Copyright: --
- Author: Adrien Lavoillotte
- Date: 19/02/04 15:55
- Description: quelques petits trucs pratique pour la programmation console en C/C++
- */
-
- /*
- *new versions of conio:
- must have this in conio.h:
- typedef enum
- {
- BLACK,
- BLUE,
- GREEN,
- CYAN,
- RED,
- MAGENTA,
- BROWN,
- LIGHTGRAY,
- DARKGRAY,
- LIGHTBLUE,
- LIGHTGREEN,
- LIGHTCYAN,
- LIGHTRED,
- LIGHTMAGENTA,
- YELLOW,
- WHITE
- } COLORS;
- */
-
-
- //#include <stdlib.h>
- //system
- #include <iostream>
- //cin, cout
- #include <iomanip>
- //setw, setfill
- #include <stdio.h>
- //fprint, fopen, FILE*, kbhit, fflush
- #include <conio.c>
- //getchar, clrscr, textcolor, getch
- //couleurs dont on se sert: cf conio.h
- #include <unistd.h>
-
- using namespace std;
-
- typedef unsigned char BYTE;
-
- int main(int argc, char *argv[])
- {
- char cChoice=0;
- BYTE cCaract = (BYTE) 0;
-
- printMenu:
- clrscr();
- textcolor(LIGHTGREEN);
- //réinitialisation nécessaire en cas de multiples opérations
- //sinon on ne peut plus quitter:
- cChoice=0; cCaract = (BYTE) 0;
- cout << " SPECHAR v.0.1 " << endl
- << "1. Voir tableau ASCII Console/MS-DOS" << endl
- << "2. Entrer un caract" << '\x8a' << "re pour obtenir son code ASCII" << endl
- << "3. Entrer un code ASCII hexa pour obtenir le caract" << '\x8a' << "re." << endl
- << "4. Entrer un code ASCII d" << '\x82' << "cimal pour obtenir le caract" << '\x8a' << "re." << endl
- << "5. Conseils - A propos de..." << endl
- << "Autre: quitter." << endl;
- textcolor(LIGHTBLUE);
- cout << "Votre choix: ";
-
- //anciennement: scanf("%u", &cChoice);
- cChoice = getch();
- fflush(stdin);
- clrscr();
- if(cChoice < 49 || cChoice > 53) // de '1' à '5'
- return 0;
-
- switch(cChoice)
- {
-
- //tableau ASCII
- case '1':
- textcolor(LIGHTGREEN);
- cout << noshowbase << "Table des caract" << '\x8a' << "res 0-127:" << endl;
- for(unsigned int i=0; i<128; i++)
- {
- cout << (char) i << " "
- << dec << setfill('0') << setw(3) << i << " "
- << hex << setw(2) << i;
- if(((i+1)%8)==0)
- cout << endl;
- else
- cout << " ";
- }
- getchar(); fflush(stdin); clrscr();
- cout << "Table des caract" << '\x8a' << "res 128-255:" << endl;
- for(unsigned int i=128; i<256; i++)
- {
- cout << (char) i << " "
- << dec << setfill('0') << setw(3) << i << " "
- << hex << setw(2) << i;
- if(((i-127)%8)==0)
- cout << endl;
- else
- cout << " ";
- }
- break;
-
- //Caractère => ASCII hex & dec
- case '2':
- textcolor(LIGHTBLUE);
- cout << "Caract" << '\x8a' << "re recherch" << '\x82' << ": ";
- //anciennement scanf("%c", &cCaract);
- //ne permettait pas 'entrée', 'droite', etc...
- cCaract = getch();
- textcolor(LIGHTGREEN);
- cout << endl << "Correspondance console/MS-DOS ASCII: "
- << endl << " d" << '\x82' << "cimale: " << dec << (int) cCaract
- << endl << " hexad" << '\x82' << "cimale: " << hex << showbase << (int) cCaract << endl;
- cCaract = 0;
- break;
-
- //hex => Caract.
- case '3':
- textcolor(LIGHTBLUE);
- cout << "Valeur ASCII hexad" << '\x82' << "cimale (2 chiffres hexa en minuscules, sans le '0x'): ";
- scanf("%hx", &cCaract);
- textcolor(LIGHTGREEN);
- cout << "Correspondance console/MS-DOS caract" << '\x8a' << "re: " << cCaract << endl;
- break;
-
- //dec => Caract.
- case '4':
- textcolor(LIGHTBLUE);
- cout << "Valeur ASCII d" << '\x82' << "cimale: ";
- scanf("%hu", &cCaract);
- textcolor(LIGHTGREEN);
- cout << "Correspondance console/MS-DOS caract" << '\x8a' << "re: " << cCaract << endl;
- break;
-
- //Conseil, à propos de...
- case '5':
- textcolor(LIGHTGREEN);
- cout << "2 fa" << '\x87' << "ons principales d'utiliser ces correspondance pour "
- << "obtenir les accents en mode console dans vos programmes C/C++:" << endl;
- textcolor(LIGHTGRAY);
- cout << "cout << \"lettre accentu\\x82\" << \"e...\"; "
- << endl << "printf(\"lettre accentu%ce...\", '\\x82'); ";
- textcolor(LIGHTGREEN);
- cout << endl << endl << "SPECHAR version 0.1"
- << endl << " par Adrien Lavoillotte (streetpc at free.fr)"
- << endl << endl << "Vous pouvez utiliser, modifier, distribuer ce programme " << '\x85' << " vos risques et perils ;-)";
- break;
- default:
- //normalement jamais atteind ;-)
- textcolor(RED);
- cout << "oops...";
- getchar();
- return 0;
- }
- fflush(stdin); getchar();
- goto printMenu;
- return 0;
- }
/*
Name: SPECHAR
Version: 0.2
Copyright: --
Author: Adrien Lavoillotte
Date: 19/02/04 15:55
Description: quelques petits trucs pratique pour la programmation console en C/C++
*/
/*
*new versions of conio:
must have this in conio.h:
typedef enum
{
BLACK,
BLUE,
GREEN,
CYAN,
RED,
MAGENTA,
BROWN,
LIGHTGRAY,
DARKGRAY,
LIGHTBLUE,
LIGHTGREEN,
LIGHTCYAN,
LIGHTRED,
LIGHTMAGENTA,
YELLOW,
WHITE
} COLORS;
*/
//#include <stdlib.h>
//system
#include <iostream>
//cin, cout
#include <iomanip>
//setw, setfill
#include <stdio.h>
//fprint, fopen, FILE*, kbhit, fflush
#include <conio.c>
//getchar, clrscr, textcolor, getch
//couleurs dont on se sert: cf conio.h
#include <unistd.h>
using namespace std;
typedef unsigned char BYTE;
int main(int argc, char *argv[])
{
char cChoice=0;
BYTE cCaract = (BYTE) 0;
printMenu:
clrscr();
textcolor(LIGHTGREEN);
//réinitialisation nécessaire en cas de multiples opérations
//sinon on ne peut plus quitter:
cChoice=0; cCaract = (BYTE) 0;
cout << " SPECHAR v.0.1 " << endl
<< "1. Voir tableau ASCII Console/MS-DOS" << endl
<< "2. Entrer un caract" << '\x8a' << "re pour obtenir son code ASCII" << endl
<< "3. Entrer un code ASCII hexa pour obtenir le caract" << '\x8a' << "re." << endl
<< "4. Entrer un code ASCII d" << '\x82' << "cimal pour obtenir le caract" << '\x8a' << "re." << endl
<< "5. Conseils - A propos de..." << endl
<< "Autre: quitter." << endl;
textcolor(LIGHTBLUE);
cout << "Votre choix: ";
//anciennement: scanf("%u", &cChoice);
cChoice = getch();
fflush(stdin);
clrscr();
if(cChoice < 49 || cChoice > 53) // de '1' à '5'
return 0;
switch(cChoice)
{
//tableau ASCII
case '1':
textcolor(LIGHTGREEN);
cout << noshowbase << "Table des caract" << '\x8a' << "res 0-127:" << endl;
for(unsigned int i=0; i<128; i++)
{
cout << (char) i << " "
<< dec << setfill('0') << setw(3) << i << " "
<< hex << setw(2) << i;
if(((i+1)%8)==0)
cout << endl;
else
cout << " ";
}
getchar(); fflush(stdin); clrscr();
cout << "Table des caract" << '\x8a' << "res 128-255:" << endl;
for(unsigned int i=128; i<256; i++)
{
cout << (char) i << " "
<< dec << setfill('0') << setw(3) << i << " "
<< hex << setw(2) << i;
if(((i-127)%8)==0)
cout << endl;
else
cout << " ";
}
break;
//Caractère => ASCII hex & dec
case '2':
textcolor(LIGHTBLUE);
cout << "Caract" << '\x8a' << "re recherch" << '\x82' << ": ";
//anciennement scanf("%c", &cCaract);
//ne permettait pas 'entrée', 'droite', etc...
cCaract = getch();
textcolor(LIGHTGREEN);
cout << endl << "Correspondance console/MS-DOS ASCII: "
<< endl << " d" << '\x82' << "cimale: " << dec << (int) cCaract
<< endl << " hexad" << '\x82' << "cimale: " << hex << showbase << (int) cCaract << endl;
cCaract = 0;
break;
//hex => Caract.
case '3':
textcolor(LIGHTBLUE);
cout << "Valeur ASCII hexad" << '\x82' << "cimale (2 chiffres hexa en minuscules, sans le '0x'): ";
scanf("%hx", &cCaract);
textcolor(LIGHTGREEN);
cout << "Correspondance console/MS-DOS caract" << '\x8a' << "re: " << cCaract << endl;
break;
//dec => Caract.
case '4':
textcolor(LIGHTBLUE);
cout << "Valeur ASCII d" << '\x82' << "cimale: ";
scanf("%hu", &cCaract);
textcolor(LIGHTGREEN);
cout << "Correspondance console/MS-DOS caract" << '\x8a' << "re: " << cCaract << endl;
break;
//Conseil, à propos de...
case '5':
textcolor(LIGHTGREEN);
cout << "2 fa" << '\x87' << "ons principales d'utiliser ces correspondance pour "
<< "obtenir les accents en mode console dans vos programmes C/C++:" << endl;
textcolor(LIGHTGRAY);
cout << "cout << \"lettre accentu\\x82\" << \"e...\"; "
<< endl << "printf(\"lettre accentu%ce...\", '\\x82'); ";
textcolor(LIGHTGREEN);
cout << endl << endl << "SPECHAR version 0.1"
<< endl << " par Adrien Lavoillotte (streetpc at free.fr)"
<< endl << endl << "Vous pouvez utiliser, modifier, distribuer ce programme " << '\x85' << " vos risques et perils ;-)";
break;
default:
//normalement jamais atteind ;-)
textcolor(RED);
cout << "oops...";
getchar();
return 0;
}
fflush(stdin); getchar();
goto printMenu;
return 0;
}