delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/10/19/15:33:50

From: "A. Sinan Unur" <asu1 AT cornell DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: getkey()
Date: 19 Oct 2001 19:17:56 GMT
Organization: Cornell University
Lines: 31
Sender: asu1 AT cornell DOT invalid (on 128.253.251.163)
Message-ID: <Xns913F9BA0E869DASINANUNUR@132.236.56.8>
References: <9qpj2s$96v$1 AT cyan DOT nl DOT gxn DOT net> <Xns913F803093AC5ASINANUNUR AT 132 DOT 236 DOT 56 DOT 8> <9qpp2o$b1t$1 AT cyan DOT nl DOT gxn DOT net>
NNTP-Posting-Host: 128.253.251.163
X-Trace: news01.cit.cornell.edu 1003519076 19859 128.253.251.163 (19 Oct 2001 19:17:56 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 19 Oct 2001 19:17:56 GMT
User-Agent: Xnews/4.06.22
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

"Bart van den Burg" <bart AT bart99 DOT tmfweb DOT nl> wrote in
news:9qpp2o$b1t$1 AT cyan DOT nl DOT gxn DOT net: 

> the program gives me no compilation errors at all (compliled with
> -Wall) I could be wrong here but:
> you have "(int)variable" which is the same as "int(variable), so
> "(char)variable" is similar to "char(variable)"?

no that is so fundamentally wrong, i do not know how to begin.

(int) variable

means cast the variable to int no matter what it was before.

on the other hand, int(x), and this only exists in C++, AFAIK, means create 
a new integer with the initial value x.

in this case, you are not trying to intialize a new char out of x, but jsut 
use the value of x.

>  sprintf(buffer, "%c", char(x));

you definitely should use snprintf, however, instead of sprintf.
or better yet, use a C++ solution if you are working in C++.

Sinan.

-- 
--------------------------------
A. Sinan Unur
http://www.unur.com/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019