display degree symbol in N++
-
I am using N++:
Notepad++ v8.4.8 (32-bit)
Build time : Dec 24 2022 - 19:30:12
Path : C:\Program Files (x86)\Notepad++\notepad++.exe
Command Line : “C:\temp\P08475\beta\2GaseousFuels_L6A_2021-02-18-132922.calong.out”
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 21H1
OS Build : 19043.1083
Current ANSI codepage : 1252
Plugins :
mimeTools (2.9)
NppConverter (4.5)
NppExport (0.4)I am trying to export degree symbol (plus other extended characters) using VS2019/C++:
int n = fprintf(fpos, " °\n");
n = fwprintf(fpos, L" °\n");
int n1 = sizeof(’ ‘);
fwrite(" °\n", sizeof(’ '), sizeof(" °\n"), fpos);
int n2 = sizeof(‘°’);
fwrite(" °\n", sizeof(‘°’), sizeof(" °\n"), fpos);
fflush(fpos);In the N++ display I get a black box containing “xB0” which if I paste into a google search displays correctly as the degree symbol. The encoding shows up as UTF-8 in the lower right hand corner. Which I think is correct (?). Also in the Encoding drop down.
How do I get these to display correctly or what do I need to change in writing them out?
-
This post is deleted! -
@Alan-Sayre said in display degree symbol in N++:
I am using N++:
Notepad++ v8.4.8 (32-bit)
Build time : Dec 24 2022 - 19:30:12
Path : C:\Program Files (x86)\Notepad++\notepad++.exe
Command Line : “C:\temp\P08475\beta\2GaseousFuels_L6A_2021-02-18-132922.calong.out”
Admin mode : OFF
Local Conf mode : OFF
Cloud Config : OFF
OS Name : Windows 10 Enterprise (64-bit)
OS Version : 21H1
OS Build : 19043.1083
Current ANSI codepage : 1252
Plugins :
mimeTools (2.9)
NppConverter (4.5)
NppExport (0.4)I am trying to export degree symbol (plus other extended characters) using VS2019/C++:
int n = fprintf(fpos, " °\n");
n = fwprintf(fpos, L" °\n");
int n1 = sizeof(’ ‘);
fwrite(" °\n", sizeof(’ '), sizeof(" °\n"), fpos);
int n2 = sizeof(‘°’);
fwrite(" °\n", sizeof(‘°’), sizeof(" °\n"), fpos);
fflush(fpos);In the N++ display I get a black box containing “xB0” which if I paste into a google search displays correctly as the degree symbol. The encoding shows up as UTF-8 in the lower right hand corner. Which I think is correct (?). Also in the Encoding drop down.
How do I get these to display correctly or what do I need to change in writing them out?
Looking at a source file that contains those characters looks fine to me.
If what you really meant is “I ran the c/c++ code that I should from VS, and then opened the file it created in Notepad++”, then probably your C program has a bug in what it’s writing.
“xB0” which if I paste into a google search displays correctly as the degree symbol.
Please note that the codepoint U+00B0 is the degree symbol. But if you just have the byte 0xB0 in a UTF file, it is not the degree symbol – it’s actually invalid UTF-8 on its own, which is why Notepad++ is dispaying just the byte value in a black box.
What’s probably happening is that C/C++ defaults to outputting ANSI files (Win1252 or similar), and in Win1252, U+00B0 is at byte 0xB0, so it will output a single byte. When in reality, if you want a UTF-8 file, you are going to have to ask C/C++ to encode your ANSI string as a series of UTF-8 bytes, in which U+00B0 is encoded as the two bytes 0xC2 0xB0. If you do not know how to program C/C++ so that it writes c-strings as UTF-8 bytes into a file, you will have to find a generic programming forum (like stackexchange) to ask such questions; we are not a programming help forum, so this is not the right place for such questions.
If you are really intending to read the file as the ANSI file that has been generated (Win1252 or ISO 8859-1 or similar), and Notepad++ has just mis-identified it as UTF-8, you can use Encoding > ANSI to tell Notepad++ to re-interpret the bytes in the file as ANSI rather than as UTF-8: if I have:
and then use Encoding > ANSI,
it will re-interpret it as
But my guess is you have a coding problem on your end, rather than a problem with Notepad++.
Good luck.
-
@Alan-Sayre There are two degree symbols. The ANSI \0xB0 and the Unicode U+00B0 which is often encoded in UTF-8 and so you will see \xC2\xB0 in the byte stream.
In this case we are dealing with the same character value, \0xB0, but either encoded, or expected to be encoded, as either \0xB0 or \xC2\xB0 in the byte stream. Something that expects you to be using UTF-8’s \xC2\xB0 can display something like a black box containing “xB0” if you try to get it to display an ANSI \0xB0 instead of the expected UTF-8 \xC2\xB0.
This encoding mess can crop up in source code, the C++ compiler you are dealing with, when your compiled code is outputing text, and when you are copy/pasting from one place to another with encoding happening on both the copy and the paste.
I deal with it in my own code by sticking to plain ASCII in source files and tend to spell out the word “degrees” rather than attempting to battle out trying to get a
°
to reliably display everywhere and at all times.If you are creating a Windows GUI or console app then you also need to consider the codepage. The default so called OEM/ANSI character set expects you to use \0xB0 but the UTF-8 code page expects you to use \xC2\xB0. The end user can switch the code page using
chcp
(change code page) meaning your output results will vary depending on the chcp setting.Notepad++ can be a useful tool but it is not 100% reliable at detecting the encoding of a file and/or detecting the encoding as you copy/paste data into or our of Notepad++.
Essentially, you are in the middle of minefield and can’t see the mines. When in this situation I tend to do hex dumps and/or debug dumps of the data I’m working with as hex so that I can see if I’m dealing with a single \xB0 or the \xC2\xB0 byte pair at that moment. Eventually you will discover a path through the minefield that seems to work. It’s hard to know if the path chosen will always work. Good luck.
-
Thanks!
That indeed fixes the display issue. I am embarassed, I thought I had tried that.
-
This post is deleted! -
@mkupper said in display degree symbol in N++:
sticking to plain ASCII in source files and tend to spell out the word “degrees” rather than…
While this is a “solution” it is a hard sell in 2024. :-)
…attempting to battle out trying to get a ° to reliably display everywhere and at all times.
I don’t know if it is a “battle”, it is merely “considering one’s data” which you should do at all times anyway.
EDIT: Didn’t realize that this was a “thread revival”, but I don’t recall reading this before…
-
press alt and 0176 on the keyboard to insert the degree sign
-
@William-C said in display degree symbol in N++:
press alt and 0176 on the keyboard to insert the degree sign
It isn’t about “inserting” it, it’s about “displaying” it, as the topic title text and previous discussion clearly shows.