Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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", '​');

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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);
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading