Download Pelles C here: http://www.pellesc.se
Quote from: Robert on January 18, 2026, 12:17:30 AMThe RTF output from this code is different from the RTF output of John Z's IDE addin.It might just created for different purbose, like writing to RichEdit control.
int printf(const char * restrict format, ...);
// https://stackoverflow.com/questions/5603559/one-file-lib-to-conv-utf8-char-to-wchar-t
short utf8_to_wchar(char **utf8)
{
short sz = 0;
short c;
char *p = *(char **)utf8;
char v = (*p);
if (v >= 0)
{
c = v;
sz += c;
++p; (*utf8)++;
}
int shiftCount = 0;
if ((v & 0xE0) == 0xC0)
{
shiftCount = 1;
c = v & 0x1F;
}
else if ((v & 0xF0) == 0xE0)
{
shiftCount = 2;
c = v & 0xF;
}
else
return 0;
++p; (*utf8)++;
while (shiftCount)
{
v = *p;
++p; (*utf8)++;
if ((v & 0xC0) != 0x80)
return 0;
c <<= 6;
c |= (v & 0x3F);
--shiftCount;
}
sz += c;
return sz;
}
int ShortToStrPos(int n, char *s)
{
int i, sign, idx, nl, len;
idx = 0;
/* if ((sign = n) < 0) { // record sign
n = -n; // make n positive
idx++;
}*/
i = 0;
nl = n;
while ((nl /= 10) > 0) /* count nums */
idx++;
len = idx+1;
s[idx+1] = '\0';
do { /* generate digits in reverse order */
s[idx--] = n % 10 + '0'; /* get next digit */
} while ((n /= 10) > 0); /* delete it */
// if (sign < 0)
// s[0] = '-';
return len;
}
int __cdecl main(void)
{
char utf8[] = u8"σκατ";
char *p = utf8;
while (*p) {
if (*(unsigned char*)p > 127) { // UTF8 ?
short uc = utf8_to_wchar(&p);
printf("%Xh\t", uc);
}
}
printf("\n%p\n%p\n", utf8, p);
return 0;
}
Quote from: TimoVJL on January 17, 2026, 01:21:16 PMA small stupid C to RTF project to RichEdit.
It can help to debug some code.
-
#include <windows.h>
#include <stdio.h>
static int OrigCodePage;
static const char* σκατ;
static const char* δυσκατανοήτων;
int main(int argc, char* argv[])
{
OrigCodePage = GetConsoleOutputCP();
SetConsoleOutputCP(65001);
σκατ = "σκατ doo, be, shoo, bop, ooh, dee, doo, sha-bam";
δυσκατανοήτων = "δυσκατανοήτων difficult to understand";
printf("%s%s%s\n", σκατ, " ", δυσκατανοήτων);
_getch();
SetConsoleOutputCP(OrigCodePage);
return 1;
}
#include <windows.h>
#include <stdio.h>
static int OrigCodePage;
static const char* УКБФ;
static const char* ДХУКБФБНПЎФЩН;
int main(int argc, char* argv[])
{
OrigCodePage = GetConsoleOutputCP();
SetConsoleOutputCP(65001);
УКБФ = "УКБФ doo, be, shoo, bop, ooh, dee, doo, sha-bam";
ДХУКБФБНПЎФЩН = "ДХУКБФБНПЎФЩН difficult to understand";
printf("%s%s%s\n", УКБФ, " ", ДХУКБФБНПЎФЩН);
_getch();
SetConsoleOutputCP(OrigCodePage);
return 1;
}
Page created in 0.023 seconds with 11 queries.