SohX33
SohX33

Reputation: 3

Why does printing multiple zero width spaces print less than expected in C?

The program below is supposed to print A, 100 zero width spaces or '0x200B' and then print B, but when I execute it, it prints 10 zero width spaces instead

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main() {
    setlocale(LC_CTYPE, "");
    wchar_t space = 0x200B;

    wprintf(L"A");

    for (int i = 0; i < 100; i++) {
        wprintf(L"%lc", space);
    }

    wprintf(L"B");
}

I count these by copy pasting the output from the bash terminal into a online char counter so there. Why does this happen if it happens to anyone else at all?

Upvotes: 0

Views: 83

Answers (0)

Related Questions