Unicode/UTF-8 -- Going Beyond ASCII
Here's a simple program that prints (on any ASCII or Unicode machine):
1) the numeric value of any ASCII character;
2) the ASCII character corresponding to any numeric value in the ASCII character set.
Code:
#include <stdio.h>
int main (int argc, const char * argv[]) {
int c1=0, c2=0;
printf("Type any ASCII character here:");
scanf("%c",&c1);
printf("Type any ASCII numeric value:");
scanf("%d",&c2);
printf("\nThe character '%c' has an ASCII numeric value of '%d.'\nThe numeric value '%d' represents the ASCII character '%c.'",c1,c1,c2,c2);
return 0;
}
The question is: How can I modify this code to handle Unicode/UTF-8 characters beyond ASCII?
I've spent many hours googling and reading and experimenting, but my code continues to fail.
I added wide character header files and changed the format specifier, for example:
Code:
#include <wchar.h>
….
….
printf("%ls...")
but that failed.
I realize that many experienced programmers don't know how to implement Unicode/UTF-8, but I'm a noob,
so it's particularly difficult for me! I'd greatly appreciate any help with actual code snippets.