2011年3月11日 星期五

load unicode file

#include <stdio.h>
#include <stdlib.h>
#include <locale.h> //function: setlocale
#include <ctype.h>  //define WEOF

/*
 * 
 */
int main(int argc, char** argv) {
    setlocale(LC_CTYPE, "");    //all printf is encode by unicode

    FILE *fp;
    fp = fopen("file.txt", "rb");//load UTF16-LE
    fseek(fp, 0, SEEK_SET);
    if (fp) {
        wchar_t c = L' ';
        while ((c = fgetwc(fp)) != WEOF)
        {
            printf("%lc\n", c);
        }
        fclose(fp);
    }
    return (EXIT_SUCCESS);
}

沒有留言: