| #ifndef _GNU_SOURCE | |
| # define _GNU_SOURCE 1 | |
| #endif | |
| #include <locale.h> | |
| #include <stdio.h> | |
| #include <stdlib.h> | |
| #include <string.h> | |
| #include <wchar.h> | |
| int main(int argc, char *argv[]) | |
| { | |
| setlocale(LC_ALL, ""); | |
| mbstate_t ps; | |
| const char *argv1 = argv[1]; | |
| int n = strlen(argv1); | |
| wchar_t *wargv = (wchar_t *)malloc(sizeof(wchar_t)*n); | |
| memset(&ps, 0, sizeof ps); | |
| size_t g = mbsrtowcs(wargv, &argv1, n, &ps); | |
| if (g == (size_t)-1) | |
| fprintf(stderr, "invalid multibyte sequence has been encountered\n"); | |
| else | |
| for (int i = 0; i < g; i++) | |
| printf("%lc: %d\n", wargv[i], wcwidth(wargv[i])); | |
| free(wargv); | |
| return 0; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
MaskRay commentedMar 12, 2016
cc a.c -o a ./a $'\U1f632中a0 x'