A couple of things. First, since performance doesn't matter here, wouldn't it be
simpler to convert to wide character form by using mbstowcs, do the work in
wide-character form, and then convert back via wcstombs? The resulting code
should be easier to maintain, I'd think.
Also, please stick to GNU style for operator spacing and parenthesization.
Thanks.