john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

win wchar from char mbstowcs string to windows

/* 2010-05-17 johnpfeiffer 
convert-string (ansi char to wide char) 
wchar_t (32 bit) is the default for windows programs */


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main( int argc, char* argv[] )
{
    int charCount;
    char ansichars[100];
    wchar_t widechars[100];

    strcpy( ansichars , "test" );
    printf("multi character array = %s\n" , ansichars );

    /* multi byte string to wide char string  
       fun trivia, many c functions parameters resemble:
       destination = source */
    charCount = mbstowcs( widechars , ansichars , 100);
    printf("%d chars from multi wide character array after mbstowcs() = %ls\n", charCount , widechars);

/* nChars = wcstombs( ansichars , widechars , 100); */

    return 0;
} /* end main */


/* sprintf appends a null char to the end */
/* 
char temp[16];
wchar wtemp[16];
sprintf( temp ,"%d", i); 
wsprintf( wtemp , "hello" )
*/

  • « windows dirlist
  • css basics class override priority »

Published

May 17, 2010

Category

c

~104 words

Tags

  • c 95
  • char 3
  • from 24
  • mbstowcs 1
  • string 18
  • to 63
  • wchar 4
  • win 19
  • windows 72