tasken2
Messages postés7Date d'inscriptiondimanche 5 septembre 2004StatutMembreDernière intervention14 novembre 2007
-
11 nov. 2007 à 03:05
tasken2
Messages postés7Date d'inscriptiondimanche 5 septembre 2004StatutMembreDernière intervention14 novembre 2007
-
14 nov. 2007 à 20:07
bonjour à tous et merci d'avoir cliquez sur moi .
Alors voila j'ai un probleme pour récuperer la valeur du code ascii dun caractere speciaux
mais le resultat n'est pas celui que j'attends quelqu un peut mexpliquer pourquoi ?
je voudrais qu'il maffiche le code ascii de Ö et il maffiche -99 ..
je crois que c un probleme de charset siouplait alaide !
voici mon programe :
MAIN.c
<hr size="2" width="100%" />
#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <string.h>
#include "charset.h"
int main(int argc,char* argv[],int iNbArg,char ** capArg)
{
// Chaîne Iso8859-1
printf("declaration des variable\n");
PAUSE();
long i = 1;
char password[]=("klbmfgh");
long j=0;
long k=0;
long pwdec[]={0};
char url[]="";
char verify[]="";
char *decode[17]={0};
int caracActuel= 0;
char copycaeascii[100]={0};
char caSrc[]="ÖØÄÚÞÌ×îè×ÏÞÓÝèòØ";/* var unknown */
int iStrLen = strlen(caSrc),ret;
FILE *unknown=NULL;
printf("Transformation du contenu de la variable unknown en ASCII\n");
PAUSE();
char caEAscii[iStrLen];
ret = iso8859ToEascii(caSrc,iStrLen,caEAscii,iStrLen);
caEAscii[ret] = 0;
printf("Extended Ascii: %s\n",caEAscii);/* EXTENDED ASCII */
strcpy(copycaeascii,caEAscii); printf("var unknown %s\n",copycaeascii); /* var unknown copycaeascii */
PAUSE();
for (k=0;k < strlen(caSrc); k++)
{
}
PAUSE();
printf("la valeur de decode est : %s\n",decode);
if (strcmp(copycaeascii,caEAscii) == 0)
{
printf("la copy de unknow est identique a la valeur de unknown soit :\n%c\n",copycaeascii[1]);
PAUSE();
printf("le code ascii de %c est %d\n",copycaeascii[1],copycaeascii[1]);
PAUSE();
}
else
{
printf("les chaine ne sont pas identique\n");
}
system("pause");
return 0;
}
CHARSET.h :
<hr size="2" width="100%" />
#ifndef UNICODE
#define UNICODE
#define wchar unsigned short // Unicode is encoded in 16 bits
int strcmp(const char* chaine1, const char* chaine2);
unsigned int easciiToIso8859(const char * capSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen);
unsigned int iso8859ToUnicode(const char * capSrc,unsigned int iSrcLen,wchar * wcapDest,unsigned int iDestLen);
unsigned int unicodeToUtf8(const wchar * wcapSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen);
unsigned int utf8ToUnicode(const char * capSrc,unsigned int iSrcLen,wchar * wcapDest,unsigned int iDestLen);
unsigned int unicodeToIso8859(const wchar * wcapSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen);
unsigned int iso8859ToEascii(const char * capSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen);
#endif
CHARSET.C
<hr size="2" width="100%" />
/**
* Functions to Convert beetween different charset
* author Julien Folly
* version 1.0
*/
/**
* Convert from Extended ascii to ISO 8859-1
* Return iSrcLen, DEST_TOO_SMALL if the destination is too small, or
* INCOMPATIBLE_EASCII if it's impossible to convert from eascii to ios8835
* The iDestLen should be equal to iSrcLen
*
* capSrc -> Pointer to the string to convert
* iSrcLen -> Number of character in capSrc
* capDest -> Pointer to an allocated memory area for the converted string
* iDestLen -> Size of the allocated memory area
*/
unsigned int easciiToIso8859(const char * capSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen){
if(iDestLen < iSrcLen) return DEST_TOO_SMALL;
unsigned int i,ret = iSrcLen;
for(i 0 ; i ASCII) ret INCOMPATIBLE_EASCII;
capDest[i] = capSrc[i];
}
}
return ret;
}
/**
* Convert from ISO 8859-1 to Unicode
* Return iSrcLen or DEST_TOO_SMALL if the destination is too small
* The iDestLen should be equal to iSrcLen
*
* capSrc -> Pointer to the string to convert
* iSrcLen -> Number of character in capSrc
* wcapDest -> Pointer to an allocated memory area for the converted string
* iDestLen -> Size of the allocated memory area
*/
unsigned int iso8859ToUnicode(const char * capSrc,unsigned int iSrcLen,wchar * wcapDest,unsigned int iDestLen){
if(iDestLen < iSrcLen) return DEST_TOO_SMALL;
unsigned int i;
for(i = 0 ; i Pointer to the string to convert
* iSrcLen -> Number of character in capSrc
* capDest -> Pointer to an allocated memory area for the converted string
* iDestLen -> Size of the allocated memory area
*/
unsigned int unicodeToUtf8(const wchar * wcapSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen){
if(iDestLen == 0) return DEST_TOO_SMALL;
unsigned int iNbUTF8 = 0;
unsigned int i;
for(i = 0 ; i iDestLen) return DEST_TOO_SMALL;
}else
/**
* Convert from UTF8 to unicode
* Return the number of character, DEST_TOO_SMALL if the destination is too small,
* or UTF8_BAD_STRING if the UTF8 String is invalid
* The iDestLen should be equal to iSrcLen
*
* capSrc -> Pointer to the string to convert
* iSrcLen -> Number of byte in capSrc
* wcapDest -> Pointer to an allocated memory area for the converted string
* iDestLen -> Size of the allocated memory area
*/
unsigned int utf8ToUnicode(const char * capSrc,unsigned int iSrcLen,wchar * wcapDest,unsigned int iDestLen){
if(iDestLen == 0) return DEST_TOO_SMALL;
unsigned int iNbUnicode = 0;
unsigned int i;
/**
* Convert from Unicode to ISO 8859-1
* Return iSrcLen, DEST_TOO_SMALL if the destination is too small, or
* INCOMPATIBLE_UNICODE if it's impossible to convert from unicode to ios8835
* The iDestLen should be equal to iSrcLen
*
* wcapSrc -> Pointer to the string to convert
* iSrcLen -> Number of character in capSrc
* capDest -> Pointer to an allocated memory area for the converted string
* iDestLen -> Size of the allocated memory area
*/
unsigned int unicodeToIso8859(const wchar * wcapSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen){
if(iDestLen < iSrcLen) return DEST_TOO_SMALL;
unsigned int i,ret = iSrcLen;
for(i 0 ; i> 8 > 0) ret INCOMPATIBLE_UNICODE;
capDest[i] = wcapSrc[i];
}
return ret;
}
/**
* Convert from ISO 8859-1 to Extended ascii
* Return iSrcLen, DEST_TOO_SMALL if the destination is too small, or
* INCOMPATIBLE_ISO8859 if it's impossible to convert from ios8835 to eascii
* The iDestLen should be equal to iSrcLen
*
* capSrc -> Pointer to the string to convert
* iSrcLen -> Number of character in capSrc
* capDest -> Pointer to an allocated memory area for the converted string
* iDestLen -> Size of the allocated memory area
*/
unsigned int iso8859ToEascii(const char * capSrc,unsigned int iSrcLen,char * capDest,unsigned int iDestLen){
if(iDestLen < iSrcLen) return DEST_TOO_SMALL;
unsigned int i,ret = iSrcLen;
for(i 0 ; i ASCII) ret INCOMPATIBLE_ISO8859;
capDest[i] = capSrc[i];
}
}
return ret;
}
tasken2
Messages postés7Date d'inscriptiondimanche 5 septembre 2004StatutMembreDernière intervention14 novembre 2007 12 nov. 2007 à 05:21
oui mais ya vraiment un probleme avec le charse on dirait bien
je cherche donc le code ascii des caractere de la chaine ÖØÄÚÞÌ×îè×ÏÞÓÝèòØ
seulement je cherche a ckil me donne le code ascii du jeu de caractere en windows-1252.
donc pour Ö j'aimerais qu'il me renvois 214 et pas 153 comme il le fait maintenant.
j'ai changer ca dans main.c :
<hr size="2" width="100%" />
unsigned char copycaeascii[100]={0};
et
printf("le code ascii de %c est %u\n",copycaeascii[k],copycaeascii[k]);
tasken2
Messages postés7Date d'inscriptiondimanche 5 septembre 2004StatutMembreDernière intervention14 novembre 2007 14 nov. 2007 à 20:07
Ca me donne 4294967254 je crois quec ladresse du pointeur chu pas sur.
mais ca va pour ca j'ai reussis a passer outre mon manque de compétence
char caSrc[]="ÖØÄÚÞÌ×îè×ÏÞÓÝèòØ";
long decode[17] = {214,216,196,218,222,204,215,238,232,215,207,222,211,221,232,242,216};
j'ai regarder sur google l'equivalent du code ÖØÄÚÞÌ×îè×ÏÞÓÝèòØ en windows-1252
et j'ai vu que ca faisait ca :
214,216,196,218,222,204,215,238,232,215,207,222,211,221,232,242,216
mais j'ai une variable qui va devoir contenir des caractere speciaux dont je n'ai pas prédéfini a l'avance leur code decimale windows-1252.
et comme la console comprends rien a ce jeu de caractere j'ai cru compris
qu'elle utiliser l'iso 8859 chu pas sur non plus bref ..
Quelque pense que je devrais creer une fonction pour simuler le jeu de caractere windows-1252 comme Julien Folly et sa library que j'utilise ?
comment devrais je procédé