Chris
Chris

Reputation: 2417

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: Ç

Upvotes: 0

Views: 1570

Answers (2)

D&#233;j&#224; vu
D&#233;j&#224; vu

Reputation: 28850

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);

Upvotes: 2

David Ranieri
David Ranieri

Reputation: 41036

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;
}

Upvotes: 3

Related Questions