What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » C Programming Question

C Programming Question
Author: Message:
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: C Programming Question
A quick explanation of why it works:

In C, as in many programming languages, the char datatype is basically a number. Therefore, integer comparisons are possible, even without typecasts, and using %d in a printf is also perfectly valid.
As an example, take getchar(). It's signature is
code:
int getchar(void);
It gets a character from the keyboard (stdin), and returns it as unsigned. This leaves the negative values of int free for error codes.
Put simply:
0-255 is a valid character
<0 is an error.

Edit: Of course, once you've checked it's positive, you will need to typecast into a char. char is typically 8 bits, int 16/32 bits.

This post was edited on 10-04-2005 at 10:46 AM by RaceProUK.
[Image: spartaafk.png]
10-04-2005 10:46 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »

Messages In This Thread
C Programming Question - by John Anderton on 10-03-2005 at 06:48 PM
RE: C Programming Question - by Yousef on 10-03-2005 at 07:03 PM
RE: RE: C Programming Question - by Plik on 10-03-2005 at 07:06 PM
RE: C Programming Question - by John Anderton on 10-03-2005 at 07:18 PM
RE: C Programming Question - by Plik on 10-03-2005 at 07:25 PM
RE: C Programming Question - by John Anderton on 10-03-2005 at 07:33 PM
RE: RE: C Programming Question - by segosa on 10-04-2005 at 06:09 AM
RE: C Programming Question - by J-Thread on 10-03-2005 at 08:27 PM
RE: C Programming Question - by John Anderton on 10-04-2005 at 07:45 AM
RE: C Programming Question - by RaceProUK on 10-04-2005 at 10:46 AM


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On