0

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?

SohX33
  • 3
  • 2
  • What operating system and terminal program are you using? If you pipe output to a file using your Bash shell (i.e. `myprogram > file.txt`), is the file the correct size? – David Grayson Dec 30 '21 at 22:17
  • That was the solution thanks – SohX33 Dec 30 '21 at 22:19
  • Well, we didn't solve your original problem of why the online char counter gave the wrong number. We just narrowed it down. It's probably either a problem with the counter or your terminal program. (Or possibly something weird your C libary does when writing to an interactive standard output pipe.) – David Grayson Dec 30 '21 at 22:28
  • We can rule out its the charcounter's fault, when I copy paste the output from a file to the counter it gives me the expected amount of characters – SohX33 Dec 30 '21 at 22:34

0 Answers0