Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to print the microsecond symbol in C?

Tags:

c

I am trying to print the microsecond symbol in C, but I don't get any data in the output.

printf("Micro second = \230");

I also tried using int i = 230;

printf("Character %c", i);

but in vain! Any pointers?

like image 856
Sana Avatar asked Feb 20 '11 22:02

Sana


1 Answers

That depends entirely on the character encoding used by the console you're using. If you're using Linux or Mac OS X, then most likely that encoding is UTF-8. The UTF-8 encoding for µ (Unicode code point U+00B5) is 'C2 B5' (two bytes), so you can print it like this:

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

If you're on Windows, then the default encoding used by the console is code page 437, then µ is encoded as 0xE6, so you would have to do this:

printf("Micro second = \xE6");  // Windows, assuming CP 437
like image 96
Adam Rosenfield Avatar answered Oct 22 '22 18:10

Adam Rosenfield