Thread: printing wide characters to strings...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    61

    printing wide characters to strings...

    hello everyone,

    i have a for looop that iterates through an array of bytes, each two byte sequence is a 2 byte wide character, i need to print each two byte sequence to a wchar_t array. I have written some code but i need a few pointers on where to go from here:

    Code:
    	for(i = 0 ; i < name_len ; i++){
    		swprintf(&file_name[i], 1, L"%C",((((u8_t *)p->payload)[i+6] << 8) | ((u8_t *)p->payload)[i+6+1]));
    		printf("%C",file_name[i]);
    	        }
    but that yields a 00000000... etc array

    thanks for your help!

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    shouldn't you cast to uint16 before <<8 ?

    also - I'm not sure that using %C in swprintf is a right thing to print wide char
    Have you checked the docs?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Strings using special characters [ ]
    By mtronix in forum C++ Programming
    Replies: 9
    Last Post: 09-25-2007, 03:29 PM
  2. Printing different representations of characters...
    By smoothdogg00 in forum C Programming
    Replies: 3
    Last Post: 03-04-2006, 01:05 PM
  3. strings or arrays of characters?
    By Callith in forum C++ Programming
    Replies: 13
    Last Post: 12-26-2004, 11:28 AM
  4. printing char* strings
    By difficult.name in forum C Programming
    Replies: 4
    Last Post: 12-10-2004, 07:06 PM
  5. Getting weird characters in Strings
    By steve8820 in forum C Programming
    Replies: 3
    Last Post: 09-18-2001, 02:49 AM