ctype bug

Emiel Kollof emiel at gamepoint.net
Wed Jul 6 07:36:33 PDT 2005


On Wednesday 06 July 2005 15:28, Jonas Trollvik wrote:
> how come the argument to isprint is an int and not an unsigned char?
> to me it doesnt make sense at all.

Because a char can be represented by an integer. In fact, if you look at it in 
some weird way, a string in C is really just an array of integers terminated 
by a 0. So it makes sense to use an int for a single character. Also, the '' 
notation can be used.

Example:

#include <stdio.h>
int main(void)
{
	int a = 'a';
	char b = 'b';

	printf("%c = %d = 0x%0.2x\n", a, a, a);
	printf("%c = %d = 0x%0.2x\n", b, b, b);
	return;
}

%./t
a = 97 = 0x61
b = 98 = 0x62

See?

Cheers,
Emiel
-- 
TAURUS (Apr 20 - May 20)
	You are practical and persistent.  You have a dogged
	determination and work like hell.  Most people think you are
	stubborn and bull headed.  You are a Communist.
Attachment:
pgp00008.pgp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: pgp00008.pgp
Type: application/octet-stream
Size: 187 bytes
Desc: "Description: PGP signature"
URL: <http://lists.dragonflybsd.org/pipermail/commits/attachments/20050706/22ec553d/attachment-0017.obj>


More information about the Commits mailing list