1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| #include <errno.h>
#include <locale.h>
#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
int main(void) {
errno = 0;
wchar_t string[100];
setlocale(LC_ALL, "");
FILE * pfile = fopen("data.txt", "r");
if(pfile == NULL)
{
perror("fopen data.txt");
exit(EXIT_FAILURE);
}
fgetws(string, sizeof(string) / sizeof(string[0]), pfile); // might fail
fclose(pfile);
printf("String Entered: [%ls]: length: %d", string, wcslen(string)); // prints bad because CMD is not prepared for UTF-8
pfile = fopen("copy.txt", "w");
if(pfile == NULL)
{
perror("fopen copy.txt");
exit(EXIT_FAILURE);
}
fprintf(pfile, "String Entered: [%ls]: length: %d", string, wcslen(string));
fclose(pfile);
return 0;
} |
Partager