0

I'm trying to read the following text snippet from a file and display it in my terminal:

Mathematics and Sciences:

  ∮ E⋅da = Q,  n → ∞, ∑ f(i) = ∏ g(i), ∀x∈ℝ: ⌈x⌉ = −⌊−x⌋, α ∧ ¬β = ¬(¬α ∨ β),

  ℕ ⊆ ℕ₀ ⊂ ℤ ⊂ ℚ ⊂ ℝ ⊂ ℂ, ⊥ < a ≠ b ≡ c ≤ d ≪ ⊤ ⇒ (A ⇔ B),

  2H₂ + O₂ ⇌ 2H₂O, R = 4.7 kΩ, ⌀ 200 mm

However, certain characters are printed as ⍰ instead.

I'm using open() and read() to open the file by filename and read 'x' number of bytes into a character array, then I append a null terminator. I am using printf("%s", buffer) to print my character array.

My terminal displaying the output has its locale set to C.UTF-8 and the text file was saved with UTF-8 encoding on Windows 10. Do I need to account for specific character encodings when using printf()?

Mr Fake
  • 97
  • 2
  • 10
  • 5
    Sounds like your display environment's Unicode font(s) is/are incomplete. – Steve Summit Nov 02 '21 at 15:12
  • To be more specific, I was using Window's cmd.exe with a code page set to 65001. I tried out the program using Git Bash and the characters are being displayed just fine. Thanks @SteveSummit. I'll have to check if there is a patch or some fix for cmd.exe's character set. – Mr Fake Nov 02 '21 at 15:22
  • If you are using `open` and `read`, it seems strange to use `printf` instead of `write`. – William Pursell Nov 02 '21 at 15:42
  • 1
    You could find some help in this]post](https://stackoverflow.com/questions/15528359/printing-utf-8-strings-with-printf-wide-vs-multibyte-string-literals) – Ptit Xav Nov 02 '21 at 18:04

0 Answers0