473,320 Members | 1,979 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Print Extended ASCII in ANSI C

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
Dec 1 '07 #1
13 47967
ramif wrote:
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;
}

Dec 1 '07 #2
santosh wrote:
ramif wrote:
>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;
}
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.
Dec 1 '07 #3
ramif wrote:
santosh wrote:
>ramif wrote:
>>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;
}

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.

Dec 1 '07 #4
ramif wrote:
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.
Dec 1 '07 #5
santosh wrote:
>
.... 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? :-)

--
Chuck F (cbfalconer at maineline dot net)
<http://cbfalconer.home.att.net>
Try the download section.

--
Posted via a free Usenet account from http://www.teranews.com

Dec 1 '07 #6
ramif wrote:
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

--
Tor <bw****@wvtqvm.vw | tr i-za-h a-z>
Dec 1 '07 #7
In article <fi**********@registered.motzarella.orgramif <ra******@yahoo.co.ukwrites:
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.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Dec 2 '07 #8
thankx to everyone! It thought that it was much easier to print
"extended ASCII" on a Linux terminal. ANSI C is so platform depended!
Dec 2 '07 #9
ramif wrote:
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.

<<<<<

Dec 2 '07 #10
ramif wrote:
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.
Dec 2 '07 #11
ramif <ra******@yahoo.co.ukwrote:
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.)


--
<Insert your favourite quote here.>
Erik Trulsson
er******@student.uu.se
Dec 2 '07 #12
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.
Dec 3 '07 #13
On Dec 1, 7:01 pm, Tor Rustad <tor_rus...@hotmail.comwrote:
ramif wrote:
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, "");
<snip>
>
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.
}
Dec 3 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: | last post by:
Hey all, Quick question...been bugging me for some time, really. I have a console app, it does some things, and I want to save an array of text to a text file. The text consists of ASCII and...
13
by: bgbauer70 | last post by:
My appologies if this ends up being a duplicate post. For some reason the first post never showed up. I've tried about 300 iterrations of this same ability, and none of them seem to work in...
4
by: wob | last post by:
Many thanks for those who responded to my question of "putting greek char into C string". In searching for an solution, I noticed that there are more than one version of "Extended ASCII...
2
by: Martn Marconcini | last post by:
Hello there, I'm writting (or trying to) a Console Application in C#. I has to be console. I remember back in the old days of Cobol (Unisys), Clipper and even Basic, I used to use a program...
3
by: JSM | last post by:
Hi, I am just trying to port an existing simple encryption routine to C#. this routine simply adds/substracts 10 ascii characters to each character in a text file (except quotes). The routine...
3
by: chjiangwh | last post by:
hello,everybody I want to print extended ASCII codes in a windows console app. I want to print the chessboard in the console screen,using printf("%c",219) but it appears strange code. Anybody...
0
by: scorpio2002 | last post by:
Hi there! I'd like to know if there's a way to get ncurses to print extended ascii characters onto the screen. Apparently, it can't. When I use the printw() and I pass a wide character, it just...
4
by: =?Utf-8?B?Um9zaGFuIFIuRA==?= | last post by:
Hi All, I am new to C# programming; I am developing an application for recording audio data using voice modem. I am using HyperTerminal to manually process audio data. The modem when configured...
0
by: jumperbl | last post by:
I am converting hex to ASCII and one of the words has a dot in the middle, which is in the extended ascii characters. when i do this i get the ascii chars. ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, youll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shllpp 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.