How to print a microsecond character in C?

I am trying to print a microsecond character in C, but I am not getting any output.

printf("Micro second = \230"); 

I also tried using int i = 230;

 printf("Character %c", i); 

but in vain! Any pointers?

+4
source share
4 answers

It completely depends on the character encoding used by the console. If you are using Linux or Mac OS X, then this is most likely UTF-8 encoding. The UTF-8 encoding for ΞΌ (UIC encoding U + 00B5) is β€œC2 B5” (two bytes), so you can print it as follows:

 printf("Micro second = \xC2\xB5"); // UTF-8 

If you are on Windows, then the default encoding used by the console is code page 437 , then ΞΌ is encoded as 0xE6, so you will need to do this:

 printf("Micro second = \xE6"); // Windows, assuming CP 437 
+13
source

Here is the standard allowed for printing in C:

 printf("%lc", L'\u00b5'); 

If you agree with UTF-8, I would just write the code "Β΅" .

+2
source

Since you are running Mac OS, you can be sure that the terminal uses UTF-8. Therefore, raise the character palette (Edit β†’ Special characters ...), find the microsecond character there and put it directly in your line.

 int main() { printf("Β΅s\n"); } 

It will work as long as your source file is also UTF-8. Otherwise, you will need to find a code point for it (which should also be indicated in the character palette). Hover over a character to find its UTF-8 value (and excuse my French system): Example of the Mac OS special characters palette showing a code point

This means that you can use printf("\xc2\xb5") as an encoding-independent replacement for the character itself.

+1
source
  printf("%c", 230); 

works for me. I think it depends on the OS. It depends on the encoding (thanks zneak). I am on Windows.

0
source

Source: https://habr.com/ru/post/1340555/


All Articles