Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Convert Non-Unicode ASCII string to Unicode string in C program

Former Member
0 Likes
1,294

Can someone please tell me how to convert a non-unicode ascii string to a unicode string in a C program? I have the following code:

char str[128];

sprintf(str, "hello");

rfc_char_t uStr[128];

sprintfU(uStr, cU("%s"), str);

But this doesn't work. When I do a printfU(uStr), I get garbage. PLEASE...how do I do this?

Thanks.

8 REPLIES 8
Read only

Former Member
0 Likes
1,159

hi,

I'd try to set the locale with

setlocale(LC_ALL, "");

before printing unicode strings. otherwise it uses the default locale which is probably ISO-8859-1 or something which cannot display unicode.

just my 2 cents,

anton

Read only

0 Likes
1,159

That didn't change anything. I can convert from ascii to wide using the mbstowcs / wcstombs functions, but when I try to use these strings in an RFC function, the values are always blank.

Am I posting to the correct forum? I never get any answers to the questions I post here...

Is there any documentation on the UNICODE RFC? I can't find any resouces at all to help me right a Unicode RFC C program, and its getting very frustrating...

Read only

0 Likes
1,159

Sorry that it didn't help.

Maybe this one gets you further:

<a href="http://help.sap.com/saphelp_nw04/helpdata/en/22/042537488911d189490000e829fbbd/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/en/22/042537488911d189490000e829fbbd/frameset.htm</a>

Concerning your forum question: I'd say it reads ABAP Programming so you'll find few C programmers in here.

regards,

anton

Read only

0 Likes
1,159

Where is the 'C' forum?

Read only

0 Likes
1,159

sorry, i am not your personal butler. I'd try another tone otherwise you soon might not find anyone trying to help you.

over & out.

Read only

0 Likes
1,159

I am not trying to be nasty. I just wanted to know where to post 'C' questions. The arrangement of forums does not make it very obvious.

Read only

0 Likes
1,159

There is no separate 'C' forum as that is not the primary focus of this site. Hopefully there is someone out there who knows C as well as ABAP equally well who can answer your question.

If you are calling an ABAP RFC function module, do you think regenerating the stubs using the RFC SDK may generate the code that is unicode compliant? Just a thought.

Srinivas

Read only

0 Likes
1,159

I believe that the code that genh generated is Unicode compliant. I guess what I'm trying to do is mix Unicode and Ascii in the same program. I have to read an ascii string off a socket. I need to convert the string to an rfc_char_t *, and that is where things are becoming a problem. When I attempt to do that, either with a sprintfU or mbstowcs, the RFC that uses the converted string fails. The same thing happens with the login string I try to build from a config file. So my question really is, how do you convert a chart * to an rfc_chart_t * in the Unicode environment?