SEARCH YOUR SOLUTION HERE  

Lost in encoding stuff



I am a bit list in encoding related stuff. Let me explain what I am
doing (yes it's C++ ):
I am getting some input content due Expat Xml Parser. I've setup Expat
to use wchar_t.
First question is this -- what is the difference of unsigned short,
wchar_t and char
Okay, wchar_t is an built-in type of C++ and its two bytes of size
whereas char is always one byte.
But what's the real difference when storing Text into those types i.e.
ASCII, UTF-8, UTF-16 or UTF-32 encoded text
Afaik, UTF-8 is 2 bytes, UTF-16 is 2 bytes and UTF-32 is up to four
bytes Well anyway, my issue is how to correctly work with those
types. Internally I am using wchar_t for all my representations but
depending on the encoding I need to shift a current char value
bitwise, right
Okay next one -- I am storing everything of my wchar_t array into a
stream of type char, doing so by a simple memcpy. Now how could I read
it back in Say I have char* buffer where my wchar_t string is saved
in. I could surely do a simply memcpy(myWcharVar, buffer,
sizeof(wchar_t)) to get two bytes but this doesn't seem to be very
efficient as I'd like to read it char by char (like wchar_t nx =
buffer.next(), know what I mean).
And then after having read such a char, I must be able to correctly
encode it. I know the encoding whether its ASCII, UTF-8, 16 or
anything but how would I go about it *without* using any big
libraries

Posted On: Sunday 4th of November 2012 06:18:54 AM Total Views:  444
View Complete with Replies




Related Messages:

Steganography challenge, had me lost   (145 Views)
Code: #include #include #include //### This function is complete. You do not need to alter it ############################# //===== main ============================================================================= // Asks user whether they wish to extract or embed a file in a bitmap container file //======================================================================================== int main() { // prototypes void embed (void); void extract(void); // variables char choice; // Code do { printf("\nWhat would you like to do\n\n"); printf(" 1) Extract a file from an image\n"); printf(" 2) embed a file into an image\n\n"); printf(" 0) Exit\n\n"); printf(" > "); choice = getchar(); getchar(); } while ((choice !='0' ) && (choice != '1') && (choice != '2') ); if (choice == '1') extract(); if (choice == '2') embed(); getchar(); return(0); } //######################################################################################## //# Extraction //######################################################################################## //### This function is complete. You do not need to alter it ############################# //===== extract ========================================================================== //# Extacts a file from a container bmp file //======================================================================================== void extract(void) { // prototypes FILE* askAndOpen (char message[], char mode ); int BMPheaders ( FILE* image_in, unsigned char header[], unsigned char info[] ); int searchForFile(unsigned char image[], char filename[] ); void saveFile (unsigned char image[], char filename[], int im_size ); // variables FILE* image_in; unsigned char header[14]; // Array containing bmp header information unsigned char info [40]; // Array containing bmp info section unsigned char* image; // pointer to image data int imageSize; // size of data part of image. int embeddedLength; char embeddedName[80]; // code image_in = askAndOpen("Please enter name of image file: ",'r'); // open container file imageSize = BMPheaders( image_in, header, info ); // read and analyse headers of container file if ( NULL == (image = (unsigned char*)malloc(imageSize)) ) exit(5); // assign memory to store image section of container if ( imageSize != fread(image, sizeof(char), imageSize, image_in) ) exit(6); // read image section of container file. embeddedLength = searchForFile(image, embeddedName); // check if there is a file embedded in image. if (embeddedLength) saveFile (image, embeddedName, embeddedLength); // save the file which is embedded in the image section free (image); fclose (image_in); } int searchForFile(unsigned char image[], char filename[]) { // variables unsigned char leader[86]; int i; int j; char * p_leader = leader; char * p_image = image; // Code for (i=0; i
Recursion difficulties, very lost   (216 Views)
I'm working on an assignment that wants me to recursively determine the value of the nth term of a geometric sequence defined by the terms a, ar, ar^2(squared), ar^3(cubed),.....ar^n-1 It also note that the argument should be the first term a, the common ratio r, and the value of n The section in the book covers recursion very briefly and I'm struggling to figure out how to start this assignment. Any pointers or exampes to get me going would greatly be appreciated The code is not the assignment but the only skeleton the book gives of recursion Code: #include #pragma warning (disable : 4996) int main () { int n, result; int factorial (int); printf( "Enter a number: "); scanf( "%d", &n); result = factorial(n); printf( "\nThe factorial of %d is %d\n", n, result); return 0; } int factorial (int result) { result , Ah its always something so small,
Character encoding conversion programs   (573 Views)
I've written a set of these conversion programs. Please give some advices. ftp://michaeldadmum.no-ip.org/unicode.tar.bz2
standard encoding for float?   (563 Views)
Is the encoding for float platform independent That is, if I take the four bytes, stick them into an ethernet packet send them to another machine, then (after endian swapping and alignment), set a float pointer to point at those four bytes, will I get the same value It seems to work on the plaforms I have, but this is suppose to work for any machine types -- so I guess my question is, is the encoding of float standardized
any way to see the non-printable stuff in strings?   (271 Views)
Hi I'm working on a project that has a lot of string processing going on. I'm getting hung up because I can't see some of the hidden characters in my strings (\n, \r\n, \t etc etc). Is there any way to print out a string to standard out that shows these hidden characters as escape sequences instead of their literal meaning