Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ASCII characters

0 views
Skip to first unread message

jt

unread,
Sep 5, 2008, 8:07:58 AM9/5/08
to
hello everyone..,
i'm using ubuntu 8.04 OS. I'm not able to output the non-printable
ascii chatacters.
for eg.
printf("%c",1); // nothing is outputted.....

is there any way to output these characters...???

Bartc

unread,
Sep 5, 2008, 8:10:17 AM9/5/08
to

"jt" <karthi...@gmail.com> wrote in message
news:223752f0-a7a1-48fd...@i20g2000prf.googlegroups.com...

They're called non-printable for a reason.

What did you expect to see?

--
Bartc

pete

unread,
Sep 5, 2008, 8:12:34 AM9/5/08
to

You're not able to print the non-printable?
Hmm ...

--
pete

jt

unread,
Sep 5, 2008, 8:20:05 AM9/5/08
to

Bartc wrote:

when i execute the same statement in windows a smiley will be
outputted.

Chris Dollin

unread,
Sep 5, 2008, 8:26:12 AM9/5/08
to
jt wrote:

> hello everyone..,
> i'm using ubuntu 8.04 OS. I'm not able to output the non-printable
> ascii chatacters.
> for eg.
> printf("%c",1); // nothing is outputted.....

Well, presumably it's called a non-printable character because it
doesn't have a printing representation.

What do you want to see if it's non-printable? Use `isprint` to
find out if its printable or not, then decide how you want to
display a non-printing character.

#include <ctype.h>

void printCharSomehow( unsigned char ch )
{
printf( (isprint( ch ) ? "'%c'" : "char(%d)"), ch );
}

--
'It changed the future .. and it changed us.' /Babylon 5/

Hewlett-Packard Limited Cain Road, Bracknell, registered no:
registered office: Berks RG12 1HN 690597 England

Andrew Poelstra

unread,
Sep 5, 2008, 8:31:45 AM9/5/08
to
On Fri, 2008-09-05 at 05:20 -0700, jt wrote:
>
> Bartc wrote:
>
> > "jt" <karthi...@gmail.com> wrote in message
> > news:223752f0-a7a1-48fd...@i20g2000prf.googlegroups.com...
> > > hello everyone..,
> > > i'm using ubuntu 8.04 OS. I'm not able to output the non-printable
> > > ascii chatacters.
> > > for eg.
> > > printf("%c",1); // nothing is outputted.....
> > >
> > > is there any way to output these characters...???
> >
> > They're called non-printable for a reason.
> >
> > What did you expect to see?
> >
>
> when i execute the same statement in windows a smiley will be
> outputted.

Then I suppose this code only works on Windows. (And actually,
I don't even suppose /that/ for all Windows.) Your problem is
that different systems use different character sets, and your
code is critically dependent on a specific charset.

So, as a learning experience, it has been very valuable.

But in future, to write portable C code that will compile on
all different systems (at least, with minimal porting effort)
it is best to be charset-agnostic. Basically, the only thing
you can assume is that the characters '0', '1', ..., '9' are
contiguous in value. Everything else (IIRC) is allowed to
change from character set to character set.

HTH.

--
Andrew Poelstra <apoe...@wpsoftware.com>
To email me, change .net to .com in the above address.

jt

unread,
Sep 5, 2008, 8:32:46 AM9/5/08
to

please check the below link..i want to print those symbols..
http://didgood.com/programing/datatheory/ascii-0-127.gif

Andrew Poelstra

unread,
Sep 5, 2008, 8:38:36 AM9/5/08
to
On Fri, 2008-09-05 at 05:32 -0700, jt wrote:
> On Sep 5, 5:26 pm, Chris Dollin <chris.dol...@hp.com> wrote:
> > jt wrote:
> > > hello everyone..,
> > > i'm using ubuntu 8.04 OS. I'm not able to output the non-printable
> > > ascii chatacters.
> > > for eg.
> > > printf("%c",1); // nothing is outputted.....
> >
> > Well, presumably it's called a non-printable character because it
> > doesn't have a printing representation.
> >
> > What do you want to see if it's non-printable? Use `isprint` to
> > find out if its printable or not, then decide how you want to
> > display a non-printing character.
> >
> > #include <ctype.h>
> >
> > void printCharSomehow( unsigned char ch )
> > {
> > printf( (isprint( ch ) ? "'%c'" : "char(%d)"), ch );
> > }
> >
> please check the below link..i want to print those symbols..
> http://didgood.com/programing/datatheory/ascii-0-127.gif

Please don't quote signatures. I snipped Chris' for you.

You do what you want, you need to change your printing
charset to ASCII. Whether this is possible is specific
to your implementation, as are details about how to do
so. /Why/ you would ever need to do so is debatable.

Lew Pitcher

unread,
Sep 5, 2008, 8:45:35 AM9/5/08
to
On September 5, 2008 08:32, in comp.lang.c, jt (karthi...@gmail.com)
wrote:
[snip]

> please check the below link..i want to print those symbols..
> http://didgood.com/programing/datatheory/ascii-0-127.gif

Sorry, but the chart at that URL does not show ASCII. Instead, it shows a
bastardized characterset made up by Microsoft (or perhaps IBM?) that
contains /some/ features in common with ASCII, but deviates greatly from
ASCII for characters with values less than 0x20.

Perhaps the environment you compile and execute in does not use this
Microsoft/IBM bastard characterset.

--
Lew Pitcher

Master Codewright & JOAT-in-training | Registered Linux User #112576
http://pitcher.digitalfreehold.ca/ | GPG public key available by request
---------- Slackware - Because I know what I'm doing. ------


Lew Pitcher

unread,
Sep 5, 2008, 8:45:45 AM9/5/08
to
On September 5, 2008 08:07, in comp.lang.c, jt (karthi...@gmail.com)
wrote:

> hello everyone..,

What part of "non-printable" do you not understand?

For what it's worth, ASCII is divided into three types of character:
1) printable characters, including the SPACE character
2) format effectors, like CARRIAGE RETURN, LINE FEED, FORM FEED, and TAB,
3) communications effectors, like START OF HEADER, START OF TEXT, and END
OF TEXT (all used in BSC/Bisync communications protocols), ESCAPE,
SHIFT IN, and SHIFT OUT (used to select alternate glyphs), DELETE,
SUBSTITUTE (used in data correction and recovery)

(Note: these are my terms for these characters. For the official terms,
please see either the ANSI "US-ASCII" standards, or the CCITT "7 bit
characterset" standards. These two standards are interchangable, and both
describe the characterset coloqually known as "ASCII".)

For the printable characters (0x20 through 0x7e), printf() should result in
a glyph being deposited onto the display media. For the "format effectors",
printf() should not "deposit a glyph", but should instead change the
position of the /next/ glyph according to the effector. And, finally, for
the "communications effectors", printf() should (for the most part) show
neither a glyph, nor reposition for the next glyph. (In fact, the display
behaviour will be implementation-defined, and outside the scope of C to
define or influence).

Lew Pitcher

unread,
Sep 5, 2008, 8:45:49 AM9/5/08
to
On September 5, 2008 08:20, in comp.lang.c, jt (karthi...@gmail.com)
wrote:

>
>

Which goes to show how much Microsoft follows standards. :-)

Richard Heathfield

unread,
Sep 5, 2008, 8:45:58 AM9/5/08
to
Andrew Poelstra said:

<snip>



> But in future, to write portable C code that will compile on
> all different systems (at least, with minimal porting effort)
> it is best to be charset-agnostic.

I agree with this, but I left it in so I'd feel better about disagreeing
with...

> Basically, the only thing
> you can assume is that the characters '0', '1', ..., '9' are
> contiguous in value. Everything else (IIRC) is allowed to
> change from character set to character set.

...this, because you can *also* assume that the null character is
all-bits-zero, and that every member of the required source character set
will have a positive value when stored in a char.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999

Richard Bos

unread,
Sep 5, 2008, 8:48:23 AM9/5/08
to
Andrew Poelstra <apoe...@wpsoftware.net> wrote:

> Please don't quote signatures. I snipped Chris' for you.

While we're on the meta stuff, your newsreader is removing References:
headers. This is Not Good.

Richard

Bartc

unread,
Sep 5, 2008, 8:49:18 AM9/5/08
to
"jt" <karthi...@gmail.com> wrote in message
news:60ce8ed6-6d28-46f9...@r15g2000prd.googlegroups.com...

Character 1 was originally SOH control code. Windows text console will show
it as a smiley (as you've seen). Windows graphics will just show a blank.
It's anyone's guess what Linux will show. So use of these characters is
rather hit and miss.

You need to use unicode for this. I think 0x263A. Then figure out how to
show unicode using C+Linux. Or you could just use :-) :-)

--
Bartc

Lew Pitcher

unread,
Sep 5, 2008, 9:10:46 AM9/5/08
to
On September 5, 2008 08:49, in comp.lang.c, Bartc (b...@freeuk.com) wrote:

> "jt" <karthi...@gmail.com> wrote in message
> news:60ce8ed6-6d28-46f9...@r15g2000prd.googlegroups.com...
>>
>>
>> Bartc wrote:
>>
>>> "jt" <karthi...@gmail.com> wrote in message
>>>
news:223752f0-a7a1-48fd...@i20g2000prf.googlegroups.com...
>>> > hello everyone..,
>>> > i'm using ubuntu 8.04 OS. I'm not able to output the non-printable
>>> > ascii chatacters.
>>> > for eg.
>>> > printf("%c",1); // nothing is outputted.....

[snip]


>> when i execute the same statement in windows a smiley will be
>> outputted.
>
> Character 1 was originally SOH control code.

Which is the Bisync/BSC communications protocol "Start of Header" octet,
used to delimit the beginning of the BSC address (as opposed to the
beginning or ending of the data) in a bisync communications exchange. Since
ASCII was defined, SOH has been given other uses.

> Windows text console will
> show it as a smiley (as you've seen). Windows graphics will just show a
> blank. It's anyone's guess what Linux will show. So use of these
> characters is rather hit and miss.

For the most part, it is up to each execution environment to interpret these
characters by their own standards. Output 0x01 to a serial line connected
to a BSC/RJE device, and that device will expect a bisync address and data
frame to follow. Output to a Windows text console, and Windows will display
a glyph which is not part of the ASCII standard glyphs. To each his own ;-)

> You need to use unicode for this. I think 0x263A. Then figure out how to
> show unicode using C+Linux. Or you could just use :-) :-)
>

--

osmium

unread,
Sep 5, 2008, 10:18:39 AM9/5/08
to
"jt" wrote:

>please check the below link..i want to print those symbols..
>http://didgood.com/programing/datatheory/ascii-0-127.gif

I suggest a search term such as this in a google search:
linux dos glyph
That should get you started.

I think there is a typo in your refernce page. Character 096 should show
the glyph for the grave chacracter.

Trivia. Doing a similar thing on the Atari ST can produce a picture that
looks remarkably like Hugh Hefner smoking a pipe. A young Hugh Hefner. And
there is a glyph pair somewhere that can produce an integral sign, as in
integral calculus.


Keith Thompson

unread,
Sep 5, 2008, 10:55:19 AM9/5/08
to
Andrew Poelstra <apoe...@wpsoftware.net> writes:
> On Fri, 2008-09-05 at 05:32 -0700, jt wrote:
[...]

>> please check the below link..i want to print those symbols..
>> http://didgood.com/programing/datatheory/ascii-0-127.gif
>
[...]

>
> You do what you want, you need to change your printing
> charset to ASCII. Whether this is possible is specific
> to your implementation, as are details about how to do
> so. /Why/ you would ever need to do so is debatable.

No, ASCII doesn't have a smiley at position 001. The cited table does
not accurately reflect the ASCII character set.

--
Keith Thompson (The_Other_Keith) ks...@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"

Keith Thompson

unread,
Sep 5, 2008, 10:57:23 AM9/5/08
to

You already did; it just didn't display the way you expected it to.

<OT>
Your system provides ways to see your program's output in printable form.
For example, try "./my_program | cat -A" or "./my_program | od -c".
</OT>

Keith Thompson

unread,
Sep 5, 2008, 11:26:34 AM9/5/08
to
"osmium" <r124c...@comcast.net> writes:
[...]

> Trivia. Doing a similar thing on the Atari ST can produce a picture that
> looks remarkably like Hugh Hefner smoking a pipe. A young Hugh Hefner.
[...]

<WAY_OT>
I believe that's J.R. "Bob" Dobbs.
<http://en.wikipedia.org/wiki/J.R._Bob_Dobbs>
</WAY_OT>

Default User

unread,
Sep 5, 2008, 3:27:43 PM9/5/08
to
Keith Thompson wrote:

> "osmium" <r124c...@comcast.net> writes:
> [...]
> > Trivia. Doing a similar thing on the Atari ST can produce a
> > picture that looks remarkably like Hugh Hefner smoking a pipe. A
> > young Hugh Hefner.
> [...]
>
> <WAY_OT>
> I believe that's J.R. "Bob" Dobbs.
> <http://en.wikipedia.org/wiki/J.R._Bob_Dobbs>
> </WAY_OT>

I have that picture (suitably magnified) on the door of my mini-fridge
in my cubicle. Bob watches over me. As long as he's still grinning, I
figure I must be ok.


Brian

Andrew Poelstra

unread,
Sep 5, 2008, 7:24:15 PM9/5/08
to

Thanks. I'll switch back to slrn (I was using Evolution and having
all sorts of minor problems, but this one takes the cake.)

--
Andrew Poelstra apoe...@wpsoftware.com
To email me, use the above email addresss with .com set to .net

Andrew Poelstra

unread,
Sep 5, 2008, 7:26:29 PM9/5/08
to
On 2008-09-05, Richard Heathfield <r...@see.sig.invalid> wrote:
> Andrew Poelstra said:
>
><snip>
>
>> But in future, to write portable C code that will compile on
>> all different systems (at least, with minimal porting effort)
>> it is best to be charset-agnostic.
>
> I agree with this, but I left it in so I'd feel better about disagreeing
> with...
>
>> Basically, the only thing
>> you can assume is that the characters '0', '1', ..., '9' are
>> contiguous in value. Everything else (IIRC) is allowed to
>> change from character set to character set.
>
> ...this, because you can *also* assume that the null character is
> all-bits-zero, and that every member of the required source character set
> will have a positive value when stored in a char.
>

Thanks. I knew I was missing a couple of points, but I couldn't
remember which ones.

--
Andrew Poelstra apoe...@wpsoftware.com

Richard Bos

unread,
Sep 8, 2008, 10:10:03 AM9/8/08
to
"Default User" <defaul...@yahoo.com> wrote:

> Keith Thompson wrote:
>
> > "osmium" <r124c...@comcast.net> writes:
> > > Trivia. Doing a similar thing on the Atari ST can produce a
> > > picture that looks remarkably like Hugh Hefner smoking a pipe. A
> > > young Hugh Hefner.
> >

> > <WAY_OT>
> > I believe that's J.R. "Bob" Dobbs.
> > <http://en.wikipedia.org/wiki/J.R._Bob_Dobbs>
> > </WAY_OT>
>
> I have that picture (suitably magnified) on the door of my mini-fridge
> in my cubicle. Bob watches over me. As long as he's still grinning, I
> figure I must be ok.

That's what you think. That's what They want you to think. But ponder
this... is he grinning _with_ you, or _about_ you?

Trust nobody, not even (nay, especially) those who seem trustworthy.
Hail Eris.

Richard

0 new messages