How do I print the infinity symbol in C using printf

10,992

Like everyone else in the comments already mentioned, you would not be able to reliably print characters after 127 (and assuming it as ASCII) since ASCII is only defined upto 127. Also the output you see very much depends on the terminal settings (i.e. which locale it is configured to).

If you're fine using UTF-8 to print, you could give wprintf a try as shown below:

#include <stdio.h>
#include <wchar.h>
#include <locale.h>

int main()
{
    setlocale( LC_ALL, "en_US.UTF-8" );
    wprintf (L"%lc\n", 8734);
    return 0;
}

It would produce the following output:

8734 (or 0x221E) is the equivalent of the UTF-8 UNICODE character for the symbol .

Share:
10,992
Hashken
Author by

Hashken

Updated on June 04, 2022

Comments

  • Hashken
    Hashken almost 2 years

    I tried the following

    printf ("%c", 236);   //236 is the ASCII value for infinity
    

    But I am just getting garbage output on the screen.

    printf was working correctly for ASCII values less than 128. So I tried the following

    printf ("%c", 236u);  //unsigned int 236
    

    Still I am just getting garbage only. So, what should I do to make printf display ASCII values from 128 to 255.