简体   繁体   中英

Print extended ascii with write function

How do I print character 128 from extended ascii with write function in c language?

#include <unistd.h>

int main(void)
{
    int c;

    c = 128;
    write(1, &c, 1);
    return(0);
}

Output:

Ascii extended 128: Ç

Using a wchar_t :

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

int main(void)
{
    wchar_t c;

    setlocale(LC_ALL, "");
    for (c = 128; c < 256; c++) {
        wprintf(L"%lc\n", c);
    }
    return 0;
}

Write the Unicode version

uint16_t x = 0x87C3; // little endian (beware endianness matters)
write(1, &x, 2);

(a type that has 2 bytes)

To remove any endianness issue, use an array instead

uint8_t y[] = { 0xC3, 0x87 };
write(1, y, 2);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM