I'm currently rewriting (a part of) the printf()
function for a school project.
Overall, we were required to reproduce the behaviour of the function with several flags, conversions, length modifiers ...
The only thing I have left to do and that gets me stuck are the flags %C
/ %S
(or %lc
/ %ls
).
So far, I've gathered that wchar_t
is a type that can store characters on more than one byte, in order to accept more characters or symbols and therefore be compatible with pretty much every language, regardless of their alphabet and special characters.
However, I wasn't able to find any concrete information on what a wchar
looks like for the machine, it's actual length (which apparently vary based on several factors including the compiler, the OS ...) or how to actually write them.
Thank you in advance
Note that we are limited in the functions we are allowed to use. The only allowed functions are write()
, malloc()
, free()
, and exit()
.
We must be able to code any other required function ourselves.
To sum this up, what I'm asking here is some informations on how to interpret and write "manually" any wchar_t
character, with as little code as possible so that I can try to understand the whole process and code it myself.
wchar_t
can mean in your situation. On most *nix systems this would mean UTF-32. On Windows it means UTF-16. After that you need to decide what your narrowchar
is going to be. On most *nix systems it means UTF-8. The good news is that converting between Unicode representations is very well defined. – Ichthyosizeof(wchar_t)
should still work, right? – Staghound