By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,570 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,570 IT Pros & Developers. It's quick & easy.

Print Extended ASCII in ANSI C

P: n/a
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
Share this Question
Share on Google+
13 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.