Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <math.h>
- #include <locale.h>
- // #include <wchar.h>
- // #include <wctype.h>
- // funzione che ritorna un array di byte corrispondenti al valore dell'intero
- // passato come argomento (dato che un intero può essere di più byte ...)
- // si potrebbe mettere anche long x...
- char* inttobyt(int x) {
- int length = ceilf(log2f(x)/8);
- char* bytes = malloc(length);
- for (int i = length-1; i >= 0; i--) {
- bytes[i] = x % 256;
- x /= 256;
- }
- return bytes;
- }
- void printchars(void *bytes, int size) {
- // printf("%d\n", sizeof *bytes);
- unsigned char *cp = bytes;
- for (int i = 0; i < size; i++)
- putchar(cp[i]);
- putchar('\n');
- }
- void printbytes(void *bytes, int size) {
- unsigned char *cp = bytes;
- printf("%p: ", cp);
- for (int i = 0; i < size; ++i)
- printf("%02X ", *(cp + i));
- putchar('\n');
- }
- int main() {
- // wint_t wc;
- if ( setlocale( LC_CTYPE, "" ) == NULL)
- {
- fprintf( stderr,
- "Sorry, couldn't change to the system's native locale.\n");
- return 1;
- }
- // wchar_t lol = L'\u00E4';
- // wchar_t asd = L'ä';
- // putwchar(L'\u00E4');
- // putwchar((wchar_t)228);
- // putchar(0xC3);
- // putchar(0xA4);
- // putchar(0xC3A4);
- // printf("%c => MB: %X\tWC: %X\n", 'ä', 'ä', L'ä');
- // int a = 'ä';
- wchar_t b = L'ä';
- char a[2] = { };
- wctomb(a, b);
- // stampa il carattere ä (se si utilizza utf8)
- // printchars(inttobyt(0xC3A4), 2);
- // printchars(a, 2);
- unsigned char c[2] = {97,98};
- printchars(&c, 2);
- int x = 0xC3A4;
- printbytes(&x, sizeof x);
- printbytes(&a, sizeof a);
- printbytes(&c, 2);
- char d[] = "\u2603"; // snowman
- char e[] = "☃";
- printbytes(&d, sizeof d);
- printbytes(&e, sizeof e);
- /*
- while ( (wc = getwchar( )) != WEOF ) // or: (wc = getwc( stdin))
- {
- // if (wc != 0xA) printf("%d\n", wc);
- wc = towupper(wc);
- putwchar((wchar_t)wc); // or: putwc( (wchar_t)wc, stdout);
- }*/
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment