Print Extended ASCII in ANSI C


R

ramif

Is there a way to print extended ASCII in C??

I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}

thankx
 
Ad

Advertisements

S

santosh

ramif said:
Is there a way to print extended ASCII in C??

There is no guarantee to even print the ASCII characters as C is
character encoding agnostic, except for the fact that a certain basic
set of characters must be available and that the value of characters in
the range 0... 9 must be continuous.
I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}

If you are sure that your machine as support for extended characters
try:

#include <stdio.h>

int main(void) {
unsigned char c;

for (c = 32; c <= 255; c++) putc(c, stdout);
return 0;
}
 
R

Richard Heathfield

ramif said:
Is there a way to print extended ASCII in C??

Yes, but it may involve more work than you anticipated. Not all systems use
ASCII, and those that do use it may not use extended ASCII, or at least
not the extended ASCII that you want. (For example, a typical IBM PC's
extended character set depended on which code page you selected.)
I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}

Your code is not legal C. Either you're using C99 (unlikely) or you're not.
If you are, then main() - which takes advantage of the implicit int return
type for functions - is illegal; you'll need int main() at the very least,
and preferably int main(void). But if you're not using C99, then //stores
is a syntax error.

Also, you're missing <stdio.h>, so the printf invokes undefined behaviour.

Other than that, the code does what you tell it - i.e. it attempts to
display a glyph corresponding to the character code 177. What that does
depends very much on the system you are using, and C offers no guarantees
that the displayed glyph is the one you were actually after.

Without looking it up, I can't even begin to guess what glyph you were
hoping to see, but I can tell you that on some systems it's likely to
display the glyph you want, and on others this is very unlikely indeed.

To display the character you want, irrespective of the platform you are
using, you have a couple of obvious choices. One is to set up your own
character set, using arrays of strings. (Very painful, and it comes out in
huge letters!) Another way is to find or write a graphics library, and use
that to prepare a bitmap or JPEG or something, where you literally draw
the characters yourself. Again, this is probably more work than you want
to do.

So, if neither of those solutions appeals to you, your other option is to
consult the documentation for your implementation, to find out whether it
provides an extension to achieve what you want. If you need help with this
option, ask in a newsgroup devoted to your implementation or platform.
Possibilities include comp.os.ms-windows.programmer.win32 and
comp.unix.programmer.
 
R

ramif

santosh said:
There is no guarantee to even print the ASCII characters as C is
character encoding agnostic, except for the fact that a certain basic
set of characters must be available and that the value of characters in
the range 0... 9 must be continuous.


If you are sure that your machine as support for extended characters
try:

#include <stdio.h>

int main(void) {
unsigned char c;

for (c = 32; c <= 255; c++) putc(c, stdout);
return 0;
}

I tried your code, and gcc gave me the following warning:
"warning: comparison is always true due to limited range of data type"

BTW, i'm using Linux Fedora 7 running on x86_64 architecture. GCC
version is 4.1.2 20070925

Do you think that my PC supports extended ASCII??

A few month ago, i've written a Pascal program (on Windows XP) that
displays the extended ASCII and it worked without any problems.
 
S

santosh

ramif said:
I tried your code, and gcc gave me the following warning:
"warning: comparison is always true due to limited range of data
type"

Oops, bitten by the unsigned bug again!

Well change the type of 'c' to int.
BTW, i'm using Linux Fedora 7 running on x86_64 architecture. GCC
version is 4.1.2 20070925

Do you think that my PC supports extended ASCII??

A few month ago, i've written a Pascal program (on Windows XP) that
displays the extended ASCII and it worked without any problems.

As Richard said, most systems do support extended characters, but
exactly which set is currently applicable is system dependant. The C
language only guarantees that the characters in it's basic source and
execution character set are present. Beyond that everything is
implementation dependant.
 
R

ramif

Richard said:
ramif said:


Yes, but it may involve more work than you anticipated. Not all systems use
ASCII, and those that do use it may not use extended ASCII, or at least
not the extended ASCII that you want. (For example, a typical IBM PC's
extended character set depended on which code page you selected.)


Your code is not legal C. Either you're using C99 (unlikely) or you're not.
If you are, then main() - which takes advantage of the implicit int return
type for functions - is illegal; you'll need int main() at the very least,
and preferably int main(void). But if you're not using C99, then //stores
is a syntax error.

Also, you're missing <stdio.h>, so the printf invokes undefined behaviour.

Other than that, the code does what you tell it - i.e. it attempts to
display a glyph corresponding to the character code 177. What that does
depends very much on the system you are using, and C offers no guarantees
that the displayed glyph is the one you were actually after.

Without looking it up, I can't even begin to guess what glyph you were
hoping to see, but I can tell you that on some systems it's likely to
display the glyph you want, and on others this is very unlikely indeed.

To display the character you want, irrespective of the platform you are
using, you have a couple of obvious choices. One is to set up your own
to do.

So, if neither of those solutions appeals to you, your other option is to
consult the documentation for your implementation, to find out whether it
provides an extension to achieve what you want. If you need help with this
option, ask in a newsgroup devoted to your implementation or platform.
Possibilities include comp.os.ms-windows.programmer.win32 and
comp.unix.programmer.

I'm trying to use the extended ASCII as shown in this website
http://www.asciitable.com/. I'm using an x86_64 Linux (Fedora 7)

Thankx for your response.
 
Ad

Advertisements

R

Richard Heathfield

ramif said:

I'm trying to use the extended ASCII as shown in this website
http://www.asciitable.com/. I'm using an x86_64 Linux (Fedora 7)

So you have some options. One is:

#include <stdio.h>

int main(void)
{
int i;
for(i = 0; i < 4; i++)
{
puts(" * * * * * *");
putchar('\n');
puts("* * * * * *");
putchar('\n');
}
return 0;
}

Another is:

#include <stdio.h>
#include <stdlib.h>

int main(void)
{
int rc = EXIT_FAILURE;
unsigned char bmp177[] =
{
0x42, 0x4D, 0x76, 0x02, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00,
0x00, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x10, 0x00,
0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00,
0x00, 0x00, 0x40, 0x02, 0x00, 0x00, 0x12, 0x0B,
0x00, 0x00, 0x12, 0x0B, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xF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, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00,
0x00, 0x00, 0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00,
0xFF, 0xFF, 0xFF, 0x00, 0x00, 0x00
};
FILE *fp = fopen("177.bmp", "w");
if(fp != NULL)
{
fwrite(bmp177, 1, sizeof bmp177, fp);
if(!ferror(fp))
{
rc = EXIT_SUCCESS;
}
if(fclose(fp) != 0)
{
rc = EXIT_FAILURE;
}
}
return rc;
}

and then display the bitmap in whatever way seems best to you.

Alternatively, you could consult the documentation for your implementation,
to find out whether it provides an extension to achieve what you want. If
you need help with this option, ask in a newsgroup devoted to your
implementation or platform. Possibilities include
comp.os.ms-windows.programmer.win32 and comp.unix.programmer.
 
E

Erik Trulsson

ramif said:
I'm trying to use the extended ASCII as shown in this website
http://www.asciitable.com/. I'm using an x86_64 Linux (Fedora 7)

That particular extension to ASCII looks similar to the one which was
usually used with MS-DOS. It is unlikely that whichever terminal emulator
you are using uses that particular character set. Most likely it is set up
to use either ISO-8859-1 or UTF-8 which are different extensions to ASCII.

If you absolutely want to use that particular character set, you will have
to ask at some forum appropriate to you system how to set up your terminal emulator
to use that character set (if it is even possible.)
 
M

Mark McIntyre

ramif said:
Is there a way to print extended ASCII in C??

I tried to code something, but it only displays strange symbols.
here is my code:

main()
{
char chr = 177; //stores the extended ASCII of a symbol
printf("Character with an ascii code of 177: %c \n", chr);
//tries to print an ASCII symbol...

return 0;
}

This has got nothing to do with C.

Your computer's terminal display system is printing whatever is
character 177 in its display font. You'll need to figure out how to
change that font if you want to display some other character. Doing this
is NOT a C question.
 
C

CBFalconer

santosh said:
.... snip ...

If you are sure that your machine as support for extended
characters try:

#include <stdio.h>

int main(void) {
unsigned char c;

for (c = 32; c <= 255; c++) putc(c, stdout);
return 0;
}

If your machine has 8 bit bytes, has that stopped running yet? :)
 
T

Tor Rustad

ramif said:
Is there a way to print extended ASCII in C??

I tried to code something, but it only displays strange symbols.
here is my code:

At program startup, your C program perform a kind of

setlocale(LC_CTYPE, "C");

which is a minimal environment for C translation. To access
the locale-specific native environment, try calling:

setlocale(LC_CTYPE, "");


If I run the program below on Windows

#include <stdio.h>
#include <ctype.h>
#include <locale.h>
#include <limits.h>

static void print_char_page(const char *locale, int max)
{
int c;
char *loc;

if (NULL != (loc = setlocale(LC_CTYPE, NULL)) )
{
printf("locale changed from '%s', ", loc);
}

if (NULL != (loc = setlocale(LC_CTYPE, locale)) )
{
printf("to: '%s'\n", loc);
}

printf("+----+-----+---+\n");
printf("|Hex | Dec |Car|\n");
printf("+----+-----+---+\n");
for (c=0; c<max; c++)
{
if ( isprint(c) )
{
printf("| %02x | %3d | %c |\n", c, c, c);
}
}
}

int main(void)
{
/* change env to locale-specific native environment.*/
print_char_page("", UCHAR_MAX);

return 0;
}

it generates the following output:

locale changed from 'C', to: 'Norwegian (BokmÕl)_Norway.1252'
+----+-----+---+
|Hex | Dec |Car|
+----+-----+---+
| 09 | 9 | |
| 20 | 32 | |
| 21 | 33 | ! |
| 22 | 34 | " |
| 23 | 35 | # |
| 24 | 36 | $ |
| 25 | 37 | % |
| 26 | 38 | & |
| 27 | 39 | ' |
| 28 | 40 | ( |
| 29 | 41 | ) |
| 2a | 42 | * |
| 2b | 43 | + |
| 2c | 44 | , |
| 2d | 45 | - |
| 2e | 46 | . |
| 2f | 47 | / |
| 30 | 48 | 0 |
| 31 | 49 | 1 |
| 32 | 50 | 2 |
| 33 | 51 | 3 |
| 34 | 52 | 4 |
| 35 | 53 | 5 |
| 36 | 54 | 6 |
| 37 | 55 | 7 |
| 38 | 56 | 8 |
| 39 | 57 | 9 |
| 3a | 58 | : |
| 3b | 59 | ; |
| 3c | 60 | < |
| 3d | 61 | = |
| 3e | 62 | > |
| 3f | 63 | ? |
| 40 | 64 | @ |
| 41 | 65 | A |
| 42 | 66 | B |
| 43 | 67 | C |
| 44 | 68 | D |
| 45 | 69 | E |
| 46 | 70 | F |
| 47 | 71 | G |
| 48 | 72 | H |
| 49 | 73 | I |
| 4a | 74 | J |
| 4b | 75 | K |
| 4c | 76 | L |
| 4d | 77 | M |
| 4e | 78 | N |
| 4f | 79 | O |
| 50 | 80 | P |
| 51 | 81 | Q |
| 52 | 82 | R |
| 53 | 83 | S |
| 54 | 84 | T |
| 55 | 85 | U |
| 56 | 86 | V |
| 57 | 87 | W |
| 58 | 88 | X |
| 59 | 89 | Y |
| 5a | 90 | Z |
| 5b | 91 | [ |
| 5c | 92 | \ |
| 5d | 93 | ] |
| 5e | 94 | ^ |
| 5f | 95 | _ |
| 60 | 96 | ` |
| 61 | 97 | a |
| 62 | 98 | b |
| 63 | 99 | c |
| 64 | 100 | d |
| 65 | 101 | e |
| 66 | 102 | f |
| 67 | 103 | g |
| 68 | 104 | h |
| 69 | 105 | i |
| 6a | 106 | j |
| 6b | 107 | k |
| 6c | 108 | l |
| 6d | 109 | m |
| 6e | 110 | n |
| 6f | 111 | o |
| 70 | 112 | p |
| 71 | 113 | q |
| 72 | 114 | r |
| 73 | 115 | s |
| 74 | 116 | t |
| 75 | 117 | u |
| 76 | 118 | v |
| 77 | 119 | w |
| 78 | 120 | x |
| 79 | 121 | y |
| 7a | 122 | z |
| 7b | 123 | { |
| 7c | 124 | | |
| 7d | 125 | } |
| 7e | 126 | ~ |
| 82 | 130 | é |
| 83 | 131 | â |
| 84 | 132 | ä |
| 85 | 133 | à |
| 86 | 134 | å |
| 87 | 135 | ç |
| 89 | 137 | ë |
| 8a | 138 | è |
| 8b | 139 | ï |
| 8c | 140 | î |
| 8e | 142 | Ä |
| 91 | 145 | æ |
| 92 | 146 | Æ |
| 93 | 147 | ô |
| 94 | 148 | ö |
| 95 | 149 | ò |
| 96 | 150 | û |
| 97 | 151 | ù |
| 9a | 154 | Ü |
| 9b | 155 | ø |
| 9c | 156 | £ |
| 9e | 158 | × |
| 9f | 159 | Æ’ |
| a0 | 160 | á |
| a1 | 161 | í |
| a2 | 162 | ó |
| a3 | 163 | ú |
| a4 | 164 | ñ |
| a5 | 165 | Ñ |
| a6 | 166 | ª |
| a7 | 167 | º |
| a8 | 168 | ¿ |
| a9 | 169 | ® |
| aa | 170 | ¬ |
| ab | 171 | ½ |
| ac | 172 | ¼ |
| ad | 173 | ¡ |
| ae | 174 | « |
| af | 175 | » |
| b0 | 176 | â–‘ |
| b1 | 177 | â–’ |
| b2 | 178 | â–“ |
| b3 | 179 | │ |
| b4 | 180 | ┤ |
| b5 | 181 | Ã |
| b6 | 182 | Â |
| b7 | 183 | À |
| b8 | 184 | © |
| b9 | 185 | â•£ |
| ba | 186 | â•‘ |
| bb | 187 | â•— |
| bc | 188 | â• |
| bd | 189 | ¢ |
| be | 190 | ¥ |
| bf | 191 | â” |
| c0 | 192 | â”” |
| c1 | 193 | â”´ |
| c2 | 194 | ┬ |
| c3 | 195 | ├ |
| c4 | 196 | ─ |
| c5 | 197 | ┼ |
| c6 | 198 | ã |
| c7 | 199 | Ã |
| c8 | 200 | â•š |
| c9 | 201 | â•” |
| ca | 202 | â•© |
| cb | 203 | ╦ |
| cc | 204 | â•  |
| cd | 205 | â• |
| ce | 206 | ╬ |
| cf | 207 | ¤ |
| d0 | 208 | ð |
| d1 | 209 | Ã |
| d2 | 210 | Ê |
| d3 | 211 | Ë |
| d4 | 212 | È |
| d5 | 213 | ı |
| d6 | 214 | Ã |
| d7 | 215 | ÃŽ |
| d8 | 216 | Ã |
| d9 | 217 | ┘ |
| da | 218 | ┌ |
| db | 219 | â–ˆ |
| dc | 220 | â–„ |
| dd | 221 | ¦ |
| de | 222 | Ì |
| df | 223 | â–€ |
| e0 | 224 | Ó |
| e1 | 225 | ß |
| e2 | 226 | Ô |
| e3 | 227 | Ã’ |
| e4 | 228 | õ |
| e5 | 229 | Õ |
| e6 | 230 | µ |
| e7 | 231 | þ |
| e8 | 232 | Þ |
| e9 | 233 | Ú |
| ea | 234 | Û |
| eb | 235 | Ù |
| ec | 236 | ý |
| ed | 237 | Ã |
| ee | 238 | ¯ |
| ef | 239 | ´ |
| f0 | 240 | ­ |
| f1 | 241 | ± |
| f2 | 242 | ‗ |
| f3 | 243 | ¾ |
| f4 | 244 | ¶ |
| f5 | 245 | § |
| f6 | 246 | ÷ |
| f7 | 247 | ¸ |
| f8 | 248 | ° |
| f9 | 249 | ¨ |
| fa | 250 | · |
| fb | 251 | ¹ |
| fc | 252 | ³ |
| fd | 253 | ² |
| fe | 254 | â–  |
+----+-----+---+

on a UNIX/Linux, check the command

$ locale -a
 
Ad

Advertisements

D

Dik T. Winter

> I'm trying to use the extended ASCII as shown in this website
> http://www.asciitable.com/. I'm using an x86_64 Linux (Fedora 7)

For some reason that is called extended ASCII, and the page also tells
that it is the most popular... But actually I can not find what code-page
that actually is (it is in none of the code-pages I know). But you
are trying it on Linux. Presumably the character code that is used there
is ISO-8859-1. The symbol you want to print does not occur in that
character set.
 
R

ramif

thankx to everyone! It thought that it was much easier to print
"extended ASCII" on a Linux terminal. ANSI C is so platform depended!
 
S

santosh

ramif said:
thankx to everyone! It thought that it was much easier to print
"extended ASCII" on a Linux terminal. ANSI C is so platform depended!

Actually ISO C is _very_ portable as long as you program within it's
guarantees. And exact properties of extended characters are not
specified by it. ISO only guarantees the following:

(n1256.pdf)

5.2.1 Character sets

1.
Two sets of characters and their associated collating sequences shall be
de?ned: the set in which source ?les are written (the source character
set), and the set interpreted in the execution environment (the
execution character set). Each set is further divided into a
basic character set, whose contents are given by this subclause, and a
set of zero or more locale-speci?c members (which are not members of
the basic character set) called extended characters. The combined set
is also called the extended character set. The values of the members of
the execution character set are implementation-de?ned.

3.
Both the basic source and basic execution character sets shall have the
following members: the 26 uppercase letters of the Latin alphabet

A B C D E F G H I J K L M
N O P Q R S T U V W X Y Z

the 26 lowercase letters of the Latin alphabet

a b c d e f g h i j k l m
n o p q r s t u v w x y z

the 10 decimal digits

0 1 2 3 4 5 6 7 8 9

the following 29 graphic characters

! " # % & ' ( ) * + , - . / :
; < = > ? [ \ ] ^ _ { | } ~

the space character, and control characters representing horizontal tab,
vertical tab, and form feed. The representation of each member of the
source and execution basic character sets shall ?t in a byte. In both
the source and execution basic character sets, the value of each
character after 0 in the above list of decimal digits shall be one
greater than the value of the previous. In source ?les, there shall be
some way of indicating the end of each line of text; this International
Standard treats such an end-of-line indicator as if it were a single
new-line character. In the basic execution character set, there shall
be control characters representing alert, backspace, carriage return,
and new line. If any other characters are encountered in a source ?le
(except in an identi?er, a character constant, a string literal, a
header name, a comment, or a preprocessing token that is never
converted to a token), the behavior is unde?ned.

<<<<<
 
M

Mark McIntyre

ramif said:
thankx to everyone! It thought that it was much easier to print
"extended ASCII" on a Linux terminal. ANSI C is so platform depended!

*sigh*

I repeat, its nothing to do with C. This is entirely to do with the font
used by your terminal programme.

When you tell your terminal to print character 177, thats exactly what
it does. If your font contains a florin symbol there, it'll print that.
If it contains a smiley face, it'll print that.
 
E

Erik Trulsson

ramif said:
thankx to everyone! It thought that it was much easier to print
"extended ASCII" on a Linux terminal. ANSI C is so platform depended!

ANSI C is not platform dependent. "extended ASCII" is highly platform
dependent.

There exist many different character sets that are extensions to ASCII (plus a
few character sets that have nothing to do with ASCII at all.)

Which character set(s) are available varies from platform to platform, as does
the mechanisms to switch between them.

That character set you were trying to use is not one of those normally used in
the Unix world (which includes Linux.)
 
Ad

Advertisements

O

O_TEXT

BTW, i'm using Linux Fedora 7 running on x86_64 architecture. GCC
version is 4.1.2 20070925

Do you think that my PC supports extended ASCII??

A few month ago, i've written a Pascal program (on Windows XP) that
displays the extended ASCII and it worked without any problems.

It depends on if you are using old locales such as iso-8859-1, or more
extended ones such as as utf-8.
 
O

O_TEXT

Erik Trulsson a écrit :
That particular extension to ASCII looks similar to the one which was
usually used with MS-DOS.

It looks like «Page de code 850», the west european one, for DOS, but
it is not 850, because some letters are missing.

But «Code page 437» which was used on english spoken countries is more
similar to this one.

The sentences which says that 437 was the most popular one is false, as
850 was the most popular one, at least, in europe, for DOS systems.


It is unlikely that whichever terminal emulator
you are using uses that particular character set. Most likely it is set up
to use either ISO-8859-1 or UTF-8 which are different extensions to ASCII.

If you absolutely want to use that particular character set, you will have
to ask at some forum appropriate to you system how to set up your terminal emulator
to use that character set (if it is even possible.)

An other possibility is to directly write unicode/utf8 characters.


For example, thoses characters in the range 0x2500 - 0x257F

http://fr.wikipedia.org/wiki/Table_des_caractères_Unicode_(2000-2FFF)

0 1 2 3 4 5 6 7 8 9 A B C D E F
250
─ ┠│ ┃ ┄ â”… ┆ ┇ ┈ ┉ ┊ ┋ ┌ ┠┎ â”
251
┠┑ ┒ ┓ └ ┕ ┖ ┗ ┘ ┙ ┚ ┛ ├ ┠┞ ┟
252
┠ ┡ ┢ ┣ ┤ ┥ ┦ ┧ ┨ ┩ ┪ ┫ ┬ ┭ ┮ ┯
253
┰ ┱ ┲ ┳ ┴ ┵ ┶ ┷ ┸

┹ ┺ ┻ ┼ ┽ ┾ ┿
254
â•€ â• â•‚ ╃ â•„ â•… ╆ ╇ ╈ ╉ â•Š â•‹ â•Œ â• â•Ž â•
255
╠║ ╒ ╓ ╔ ╕ ╖ ╗ ╘ ╙ ╚ ╛ ╜ ╠╞ ╟
256
╠ ╡ ╢ ╣ ╤ ╥ ╦ ╧ ╨ ╩ ╪ ╫ ╬ ╭ ╮ ╯
257
╰ ╱ ╲ ╳ ╴ ╵ ╶ ╷ ╸ ╹ ╺ ╻ ╼ ╽ ╾ ╿
 
O

O_TEXT

If you absolutely want to use that particular character set, you will
An other possibility is to directly write unicode/utf8 characters.


For example, thoses characters in the range 0x2500 - 0x257F


gcc -I/usr/include/glib-2.0/ -I/usr/lib/glib-2.0/include/ a.c -lglib-2.0

../a.out

─â”│┃┄┅┆┇┈┉┊┋┌â”┎â”
â”┑┒┓└┕┖┗┘┙┚┛├â”┞┟
┠┡┢┣┤┥┦┧┨┩┪┫┬┭┮┯
┰┱┲┳┴┵┶┷┸┹┺┻┼┽┾┿
â•€â•â•‚╃╄╅╆╇╈╉╊╋╌â•â•Žâ•
â•â•‘╒╓╔╕╖╗╘╙╚╛╜â•â•žâ•Ÿ
╠╡╢╣╤╥╦╧╨╩╪╫╬╭╮╯
╰╱╲╳╴╵╶╷╸╹╺╻╼╽╾╿
â–€â–▂▃▄▅▆▇█▉▊▋▌â–â–Žâ–
â–░▒▓▔▕▖▗▘▙▚▛▜â–â–žâ–Ÿ


the main non-portable constructs are:
* it requires glib
* it assumes utf8 terminal
* it is not robust


The code is here after.
Purist will tell you there are some non portable stuff.
But at least, it work on my computer.


//this assumes glib on your system
#include <glib.h>



void print_character ( int characternumber)
{
gunichar2 buffer [2] = { 0x2500, 0 };
glong r, w;
GError e;
GError *ie=&e;
buffer[0] = characternumber ;

gchar* multibytecharacter = g_utf16_to_utf8 (buffer, 2, &r,&w,
&ie) ;
//this assume there is no transformation error.

g_printf ("%s", multibytecharacter);
//this assumes utf8 on terminal

//this assume there is no transformation error.
free( multibytecharacter);
}


int main ()
{

//printf ("%s\n", titi);
int i, j;
for (i=0; i < 10 ; i++)
{
for (j=0; j<16; j++)
{
print_character(0x2500+i*16+j);
}
g_printf ("\n");
}
return 0;
}
 
Ad

Advertisements

S

Spiros Bousbouras

At program startup, your C program perform a kind of

setlocale(LC_CTYPE, "C");

which is a minimal environment for C translation. To access
the locale-specific native environment, try calling:

setlocale(LC_CTYPE, "");
on a UNIX/Linux, check the command

$ locale -a

out_of_topic() {
man console_codes and the man page
of whichever terminal emulator he's
using might also be of help.
}
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top