473,383 Members | 1,795 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

char * to wchar_t * conversion

Hi all,

I am new to this form. I am developing an application where
I need to parse the below oracle line and extract the
UNISTR('\9091\0908\090A'abc\909B') the unicodes(utf16 codes) out of it and convert all to utf8 multi bytes.
The problem I am facing is :

1. I have the char *string. I have prefixed \x to each of the unicode in the above line.
like
string [i] = '//';
string [i + 1 ] = 'x';

Now I have the string modified as /x9091/x0909/x090Aabc/x909B.
I am passing this string to

mbstowcs(&wchar_ptr, char_ptr, length);

then i am passing wchar_ptr to

wcstombs (output_char_ptr, wchar_ptr,length);

But I am not getting the actual unicode chars or equivalent hex bytes in utf8 . I getting the same thing as above
/x9091/x0909/x090Aabc/x909B.

But if i do wchar_ptr = L"/x9091/x0909/x090Aabc/x909B". it works. constant works.

But I want to pass the dynaminc data. How to do this.?

why wcstombs is not converting the above unicodes to respective utf8 chars?


Am I doing anything wrong here. Please help me.
Aug 6 '12 #1
3 4497
weaknessforcats
9,208 Expert Mod 8TB
Expand|Select|Wrap|Line Numbers
  1. string [i] = '//';   <<<<<----------!
  2.  string [i + 1 ] = 'x';
  3.  
You cannot use a string object for Unicode. A string object has a char ( CHAR at MSFT) whereas a Unicode string has a wchar_t (WCHAR at MSFT).

The equivalent in C++ is a wstring which has wchar_t elements.

Try using that and post again. I fou are using Windows, then create your Unicode strings with a Microsoft allocator like SysAllocString and avoid the generic C++ string and wstring objects.

There's a whole chapter about this in the book Windows via C/C++ by Jeffrey Richter.
Aug 6 '12 #2
Thanks weaknessforcats for your reply.

I am on Linux unfortunately. I don;t know about the magic behind L"" it works only for static strings. It works for me. But I wanted something dynamic. I have framed the string look like sequence of hex strings. If I put under L and declare it statically it works. I see the characters (unicode) if pass it thru string without L"" it doesn't work. is there way I can do it Linux?
Aug 7 '12 #3
weaknessforcats
9,208 Expert Mod 8TB
The L is an instruction to the compiler to generate wchar_t for your literal istead of char it's no wonder it won't work during run time. In any cae I advise against using L because while it uses 16 bits for each character, ir does not encrypt the character correctly in all cases.

Here's a place to start: http://hektor.umcs.lublin.pl/~mikosm...x-unicode.html

I caution that you need to use already written API functions to parse your Unicode strings unless it is your intent to rewrite the Universe.

I would search the web for an example I could copy and change the variabe names to my own or perhaps embed the example inisde a function I would write.

Some Unicode encrytpions do not use 16 bits for each character but will use 8 or 16 depending upon the character. Unless you know the encryption you simple cannot read the string. That's why you need an already written library of functions.
Aug 7 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Marcin Kalicinski | last post by:
wchar_t c1 = wchar_t('A'); wchar_t c2 = L'A'; Is c1 equal to c2? If they are not equal, how can I create wchar_t character representing the same character as some char value? cheers,...
2
by: Peteroid | last post by:
The following code: char x_char = '0' ; String^ x_str = c_char.ToString( ) ; results in: x_str = = "48" and not:
23
by: Steven T. Hatton | last post by:
This is one of the first obstacles I encountered when getting started with C++. I found that everybody had their own idea of what a string is. There was std::string, QString, xercesc::XMLString,...
2
by: Alejandro Aleman | last post by:
Hello! i know this may be a newbie question, but i need to convert a string from System::String^ to char*, in the msdn page tells how, but i need to set to /clr:oldSyntax and i dont want it...
4
by: uday.sen | last post by:
Hi, I need to convert a string from UTF8 to wide character (wchar_t *). I perform the same in windows using: MultiByteToWideChar(CP_UTF8, 0, pInput, -1, pOutput, nLen); However, in linux...
1
by: Suman | last post by:
Hello All, Given a structure: struct s { char *name; wchar_t *surname; }; I wish to define a friend function for the above struct: std::ostream& operator<<(std::ostream& out, const s& x);
0
by: Khadar123 | last post by:
CString str,s; str = _T("DATA"); / str = "DATA"; const wchar_t *c = sPorts.GetBuffer(0); s.Format(_T("%s"),c); AfxMessageBox(s); or Printf/cout.....
1
by: George2 | last post by:
Hello everyone, Here is the code, and if I change line from static wchar_t* p = {PREFIX((wchar_t*)_TEXT("FOO"))}; to static wchar_t* p = {PREFIX(_TEXT("FOO"))};
1
by: dynature | last post by:
Hi, Any help, how to convert float to unicode string? gcvt() wont work on visual c++ 2005. Thnks in advance - nestor
5
by: Samant.Trupti | last post by:
Hi, There is one thing I am cofused about.... If I have a declareation say char str; Now if I want to change it to wchar so do I have to change it like .... wchar_t str; or double the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.