Skip to content

Instantly share code, notes, and snippets.

@honux77
Created October 23, 2014 07:11
Show Gist options
  • Select an option

  • Save honux77/cd116a55684e2c3918c0 to your computer and use it in GitHub Desktop.

Select an option

Save honux77/cd116a55684e2c3918c0 to your computer and use it in GitHub Desktop.
wchar_t example
#include <stdio.h>
#include <string.h>
#include <wchar.h>
#include <locale.h>
#include <stdlib.h>
#include <time.h>
void print_name(wchar_t all[]);
int main(void) {
srand(time(NULL));
setlocale(LC_ALL, "ko_KR.utf8");
wchar_t all[] = L"정호영구승모박재성임석현윤지수전용우김동진";
wprintf(L"%ls\n", all);
wprintf(L"length= %d\n", wcslen(all));
print_name(all);
print_name(all);
return 0;
}
void print_name(wchar_t all[]) {
wchar_t name[4];
int len = wcslen(all);
int i = 0;
int idx;
for (i = 0;i < 3; i++) {
idx = rand() % len;
name[i] = all[idx];
}
name[i] = '\0';
wprintf(L"%ls\n", name);
}
@honux77
Copy link
Copy Markdown
Author

honux77 commented Oct 23, 2014

실행 전에 리눅스 셸에서
$ export LANG=ko_KR.UTF-8
$ export LC_ALL=ko_KR.UTF-8
$ locale | egrep "LANG|LC_ALL" # 아래와 같이 나오는지 확인
LANG=ko_KR.UTF-8
LC_ALL=ko_KR.UTF-8
그리고 터미널 인코딩도 utf-8로 맞춰놓아야 합니다...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment