Accueil > > > INFOS CARACTÈRES ASCII/VALEURS POUR LA CONSOLE
INFOS CARACTÈRES ASCII/VALEURS POUR LA CONSOLE
Information sur la source
Description
Le plus simple est d'écrire le menu: 1. Voir le tableau ASCII Console/MS-DOS 2. Entrer un caractère pour connaître son code ASCII 3. Entrez un code hexa pour voir le caractère correspondant 4. Entrez un code décimal pour voir le caractère correspondant 5. Conseil - A propos de...
Source
- /*
- 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;
}
Conclusion
ATTENTION: le menu n'attends pas qu'on frappe entrée (getch).
Historique
- 14 octobre 2004 15:49:41 :
- 14 octobre 2004 15:51:16 :
Sources du même auteur
Sources de la même categorie
Commentaires et avis
|
Derniers Blogs
TECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICESTECHDAYS PARIS 2010 : CONNECTEZ VOS DONNéES à SHAREPOINT 2010 AVEC LES BUSINESS CONNECTIVITY SERVICES par ROMELARD Fabrice
Animé par: Gaetan Bouveret et Julien Chomarat Business Connectivity Services (BCS) est dans SharePoint 2010 la version 2 de Business Data Catalog (BDC dans SharePoint 2007). Il s'agit de la solution permettant de visualiser des données provenan...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice [DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE[DIVERS] SUIVRE VOS SéRIES PRéFéRéS SUR LA TOILE par orion
Comme de nombreux geek, je suis un grand amateur de série TV et je rate régulièrement des épisodes de mes séries préférés. Une solution s'offre à vous avec ce merveilleux site : Tv Gorge - www.tvgorge.com Moteur de recherche à l'appui, vous pouvez ...
Cliquez pour lire la suite de l'article par orion TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010TECHDAYS PARIS 2010 : LA BI DANS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Vincent Bellet et Baptiste Giraudier La BI dans SharePoint 2010, Les nouveaux services d'application dans SP2010 et SQL Server Reporting services 2008 R2. La BI dans SharePoint est généralisée pour tous afin de permettre à tous les coll...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010TECHDAYS PARIS 2010 : PLAN DE MIGRATION VERS SHAREPOINT 2010 par ROMELARD Fabrice
Animé par: Arnault Nouvel et Antoine Dongois Le processus à prendre : Apprendre (découvrir la plateforme) Préparer (documenter l'historique et choisir la méthode de MAJ) Test (Test de MAJ) Implémenter (Effectuer la MAJ) Valid...
Cliquez pour lire la suite de l'article par ROMELARD Fabrice
Forum
WIN APIWIN API par omarino_007
Cliquez pour lire la suite par omarino_007
Logiciels
DB-MAIN (9.1.0)DB-MAIN (9.1.0)DB-MAIN is a data-modeling and data-architecture tool. It is designed to help developers and anal... Cliquez pour télécharger DB-MAIN Xilisoft DPG Convertisseur (5.1.37.0120)XILISOFT DPG CONVERTISSEUR (5.1.37.0120)Xilisoft DPG Convertisseur offre aux fans de Nintendo DS une bonne solution leur permettant de dé... Cliquez pour télécharger Xilisoft DPG Convertisseur GraphicsGale (2.01.01)GRAPHICSGALE (2.01.01)GraphicsGale est un logiciel de PixelArt avec de nombreuse fonctionnalités permettant de réalisé ... Cliquez pour télécharger GraphicsGale Architecte 3D (Platinum 2010)ARCHITECTE 3D (PLATINUM 2010)Architecte 3D Platinium vous permet de concevoir facilement les plans votre future maison, de l'é... Cliquez pour télécharger Architecte 3D TeamViewer 5 (TeamViewer 5)TEAMVIEWER 5 (TEAMVIEWER 5)Dépanner un ami,expliquer une manipulation devient un jeu d'enfant.
Prise en main d'un autre ord... Cliquez pour télécharger TeamViewer 5
|