ccharacterzero-width-space

How do I print a zero width space character in C


I've tried using printf to print a zero width space
printf("%c", '​');

I get a warning whenever I try compiling
warning: multi-character character constant [-Wmultichar]
And when I run the program, I get whitespaces instead of the invisible character, so I placed letters in between the character to see if I get any different results, and it printed nothing printf("a%cb\n", '​');


Solution

  • The answer to this can be found from this post Printing a Unicode Symbol in C

    This will let you print any unicode character if you have the right code for it. In this case the 0 width space is 0x200B

    #include <stdio.h>
    #include <wchar.h>
    #include <locale.h>
    
    int main() {
        setlocale(LC_CTYPE, "");
        wchar_t space = 0x200B;
        wprintf(L"%lc\n", space);
    }