Created: Tue Mar 19 03:26:48 CET 2019
Last modiﬁed: Tue Mar 19 03:52:36 CET 2019
I don’t know how it works, though I kinda know it does ;( This post may not be THAT interesting since I wrote it in 10 minutes.
Okay so this will be a very short post which should apply to a range of small programs.
This post has a (short) prereq! It’s my three days old post Programming new features for ﬁle2c(1).
Basically, the goal is to get this,
echo せ | file2c -c # L'せ',L'\012'
Instead of this:
echo せ | file2c -c # 'ã','','','\012'
Just follow the steps:
wchar.h contains a definition of the
#include <wchar.h> #include <locale.h>
Now change the type of
Also, replace occurences of
Like this, at the beginning of
In the later switch statement
%lc instead of
%c. Also, don’t forget the
L preﬁx in the
linepos += printf("L'%lc'", c);
Those characters can then be printed back using
For reference, it works with
-ansi -pedantic options.
I don’t know how portable it is. I will try to do some research and compile what I ﬁnd in a blog post or a wiki article.