Article View: alt.msdos.programmer
Article #1169Re: Two C problems
From: Brian Hibbert
Date: Mon, 08 Jan 1996 14:29
Date: Mon, 08 Jan 1996 14:29
68 lines
2644 bytes
2644 bytes
csigjb@luxor.latrobe.edu.au () wrote:
>I have two C problems.
>
>PROBLEM 1 :
>
Snip....
I didn't try your program. I can't answer question 1, but I can answer
question 2.
>PROBLEM 2 :
>
>const escape=27;
>const cr=13;
>const bs=8;
>
>while (ch!=cr)
>{
> .
> .
> .
>}
>
>while (ch!=escape)
>{
> .
> .
> .
>}
>
>If I replace the 27 with \27' or the 13 with '\13' then these loops don't
>work i.e. an infinite loop results. WHY?
>
>Also if I want to do somthing like this : puts("\24 \25"); which should
>print the up and down arrows on the screen (ASCII 24 and 25), but no, it
>prints some other ASCII characters. As far as I can tell C has its own
>unique character table, at least for the control characters. WHY?
C is not using a different character table. The format string you are
using is using a different radix. According to my documentation, if you
specify an escape sequence in the format \nnn (where nnn is a 1 to 3
digit number) the number is taken as an OCTAL number. OCTAL 13 = decimal
11 and OCTAL 27 = decimal 23. Your program is looking for the wrong
values. You can also specify a number using hexadecimal notation by
using the \xnn escape sequence (where nn is 1 or 2 hex digits).
>
>Sometimes I wonder whether some one needs to go back an rewrite the damn
>language so that it works sensibly and predictably like Pascal can be
>relied upon to do.
The language has been rewritten. The rewrite is called C++. The C++
language still allows you to build broken programs using the C syntax,
but it is more strongly typed than plain C and adds new features that
allow you to avoid many problems altogether (for example the << output
operator for the I/O classes simplifies formatted output and lets you get
away from printf() and format strings).
--
***********************************************
Brian Hibbert b_hibbert@csc32.enet.dec.com
Digital Equipment Corporation
All opinions expressed are my own and should
not be assumed to be the opinion of my employer
Technical Details
Message-ID:
<4cr9nt$aq@nntpd2.cxo.dec.com>Path:
arc1-ca.pugleaf.net!nntpd2.cxo.dec.com!usenetReferences:
<4cojnn$rgd@lugb.latrobe.edu.au>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!nntpd2.cxo.dec.com!usenet From: Brian Hibbert <b_hibbert@csc32.enet.dec.com> Newsgroups: alt.msdos.programmer,comp.lang.c Subject: Re: Two C problems Date: 8 Jan 1996 14:29:17 GMT Organization: Digital Equipment Corporation Message-ID: <4cr9nt$aq@nntpd2.cxo.dec.com> References: <4cojnn$rgd@lugb.latrobe.edu.au> NNTP-Posting-Host: peo1012_port1.peo.dec.com Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Mailer: Mozilla 1.2N (Windows; I; 16bit) To: csigjb@luxor.latrobe.edu.au