While working with russian text under FreeBSD&MySQL I need to convert a string from MySQL to the Unicode format.
I've just started my way in C++ under FreeBSD , so please explain me how can I get ascii code of Char variable and also how can i get a character into variable with the specified ascii code.
I know that in Basic there is a commands for that : Asc() and Chr(), is there variant of this on C++?
I'm not sure if this is what you're asking, but you can cast a char to an int.
char c;
c='A';
printf("%d \n", (int) c);
How about trying out the examples here?
thank u guys ... just in case somebody need a solution :
#include <stdio.h>
#include <stdlib.h>
unsigned char* ASCIItoUNICODE (unsigned char ch);
unsigned int* ConvertString (unsigned char *string);
void UnicodePrint(unsigned int* Message);
int main()
{
unsigned char text[] = "������,world" ;
unsigned int *UnMess;
printf("Content-type: text/plain\n\n\n");
UnMess = ConvertString(text);
UnicodePrint(UnMess);
}
unsigned char* ASCIItoUNICODE (unsigned char ch)
{
unsigned char Val[2];
if ((ch < 192)&&(ch != 168)&&(ch != 184)) {Val[0] = 0; Val[1] = ch; return Val;}
if (ch == 168) {Val[0] = 208; Val[1] = 129; return Val;}
if (ch == 184) {Val[0] = 209; Val[1] = 145; return Val;}
if (ch < 240) {Val[0] = 208; Val[1] = ch-48; return Val;}
if (ch < 249) {Val[0] = 209; Val[1] = ch-112; return Val;}
}
unsigned int* ConvertString (unsigned char *string)
{
unsigned int size=0, *NewString;
unsigned char* Uni;
while (string[size++]!=0);
NewString = (unsigned int*)malloc(sizeof(unsigned int)*2*size-1);
NewString[0]=2*size-1;
size=0;
while (string!=0)
{
Uni = ASCIItoUNICODE(string);
NewString[2*size+1]=Uni[0];
NewString[2*size+2]=Uni[1];
size++;
}
return NewString;
}
void UnicodePrint(unsigned int* Message)
{
int size, i;
size=Message[0];
if (Message[1] == 0) i=2;
else i=1;
while (i<size)
{
printf("%C",Message);
i++;
}
}