c - Accept non ASCII characters -


consider program:

#include <stdio.h> int main(int argc, char* argv[]) {   printf("%s\n", argv[1]);     return 0; } 

i compile this:

x86_64-w64-mingw32-gcc -o alpha alpha.c 

the problem if give non ascii argument:

$ ./alpha róisín r�is�n 

how can write and/or compile program such accepts non ascii characters?

to respond alk: no, program printing wrongly. see example:

$ echo Ω | od -tx1c 0000000  ce  a9  0a         316 251  \n 0000003  $ ./alpha Ω | od -tx1c 0000000  4f  0d  0a           o  \r  \n 0000003 

the easiest way wmain:

#include <fcntl.h> #include <stdio.h>  int wmain (int argc, wchar_t** argv) {   _setmode(_fileno(stdout), _o_wtext);   wprintf(l"%s\n", argv[1]);   return 0; } 

it can done getcommandlinew; here simple version of code found @ handbrake repo:

#include <stdio.h> #include <windows.h>  int get_argv_utf8(int* argc_ptr, char*** argv_ptr) {   int argc;   char** argv;   wchar_t** argv_utf16 = commandlinetoargvw(getcommandlinew(), &argc);   int i;   int offset = (argc + 1) * sizeof(char*);   int size = offset;   (i = 0; < argc; i++)     size += widechartomultibyte(cp_utf8, 0, argv_utf16[i], -1, 0, 0, 0, 0);   argv = malloc(size);   (i = 0; < argc; i++) {     argv[i] = (char*) argv + offset;     offset += widechartomultibyte(cp_utf8, 0, argv_utf16[i], -1,       argv[i], size-offset, 0, 0);   }   *argc_ptr = argc;   *argv_ptr = argv;   return 0; }  int main(int argc, char** argv) {   get_argv_utf8(&argc, &argv);   printf("%s\n", argv[1]);   return 0; } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -