AIX

AIX

Connect with fellow AIX users and experts to gain knowledge, share insights, and solve problems.


#Power
 View Only
  • 1.  [AIX 5.3] why does my wsprintf not work ?

    Posted Wed August 09, 2006 09:58 AM

    Originally posted by: SystemAdmin


    Dear experts,

    While developping a C UNICODE application under AIX 5.3, I encountered the following problem, and after days of investigations I still could not find any solution.

    Please note that the application is full wchar_t based (not utf8) and that I could compile and run it without any problem on SunOS.
    I managed to isolate the problem into a simple c program:

    code
    #include <stdio.h>
    #include <locale.h>
    #include <wchar.h>

    int main()
    {
    wchar_t arab[4] = { 1583, 1575, 1605, 0 };
    wchar_t engl[4] = { 65, 66, 67, 0 };
    wchar_t temp[4] = { 0, 0, 0, 0 };

    printf("\n#1 copy arab into temp");
    wsprintf(temp, "%S", arab);
    printf("\narab bytes : "); for (int i=0; i<4; i++) printf("%d ", (int) arab[i]);
    printf("\ntemp bytes : "); for (int i=0; i<4; i++) printf("%d ", (int) temp[i]);
    printf("\n");

    printf("\n#2 copy engl into temp");
    wsprintf(temp, "%S", engl);
    printf("\nengl bytes : "); for (int i=0; i<4; i++) printf("%d ", (int) engl[i]);
    printf("\ntemp bytes : "); for (int i=0; i<4; i++) printf("%d ", (int) temp[i]);

    printf("\n\n");
    return 0;
    }
    [/code]

    [b]Here is the unexpected output:[/b]

    code#1 copy arab into temp
    arab bytes : 1583 1575 1605 0
    temp bytes : 32 0 0 0

    #2 copy engl into temp
    engl bytes : 65 66 67 0
    temp bytes : 65 66 67 0
    [/code]

    As you can see, the wsprintf call did NOT copy the chars coming from the arabic character set, but did it for the 65, 66, 67 (ABC)... but it copied a single white space (byte 32) instead!

    It seems it's related to the installed character sets and to the locales configuration... but then, why using wchar_t strings? This data type and the c functions using it (like wsprintf) are supposed to work whatever the language.

    so, my question are:
    • What should I do to make this example work ?
    • Are the C wchar_t functions really character set independent ? (it's the case on Windows and SunOS)
    • If necessary, how do I install and use additional character sets ?

    Thank you very much for your input about this,

    Best regards,

    Thomas Gilbert
    #AIX-Forum


  • 2.  More information

    Posted Wed August 09, 2006 06:30 PM

    Originally posted by: nagger


    While I don't pretend to understand the question, I do know you have not included:
    A) The AIX release: oslevel -r
    B) Which compiler you are using?
    C) Which compiler version?
    D) The compiler command line?

    Without this you are asking a lot to expect some answers.

    What does AIX support say? I assume you have support.
    #AIX-Forum


  • 3.  Re: [AIX 5.3] why does my wsprintf not work ?

    Posted Thu August 10, 2006 05:24 AM

    Originally posted by: SystemAdmin


    Ok, I eventually managed to make it work.

    Actually, I had several problems:

    • I had to install UTF-8 codepage sets
    • I had to call setlocale(LC_ALL, "en_US.UTF-8") in my program. I did not have to under SunOS and Windows. (or call with "" and use the LANG environment variable)
    • I had to get rid of my own libiconv.a library and use the one provided by AIX (mine was OK under SunOS and Windows)

    Thomas
    #AIX-Forum


  • 4.  Thanks for the feedback

    Posted Wed August 16, 2006 03:16 PM

    Originally posted by: nagger


    Thanks for taking the time to document the fix.
    #AIX-Forum