Skip to content

Instantly share code, notes, and snippets.

@airportyh
Created May 17, 2021 15:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save airportyh/820777e509d76b0577b23c6276f5253c to your computer and use it in GitHub Desktop.
Save airportyh/820777e509d76b0577b23c6276f5253c to your computer and use it in GitHub Desktop.
#include <wchar.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
wchar_t *filename = L"/blah/blah/wimpykid.py";
wchar_t *found = wcsrchr(filename, L'.');
int idx = found - filename;
int new_string_size = idx + 8;
wchar_t *log_filename = malloc(sizeof(wchar_t) * new_string_size);
wcsncpy(log_filename, filename, idx);
wcscpy(log_filename + idx, L".rewind");
log_filename[new_string_size - 1] = L'\0';
char *utf8 = malloc(sizeof(char) * new_string_size);
wcstombs(utf8, log_filename, new_string_size);
// wprintf(L"%d: %ls\n", new_string_size, log_filename);
printf("utf8: %s\n", utf8);
printf("Hello?\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment