Re: Signedness of char and puts()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Lynx,

> How should one print the actual value of a character?

Any of these will work:

printf("Character value of %s is %d.\n", "a", 'a');
printf("Character value of %s is %d.\n", "a", 'a' & 0xFF);
printf("Character value of %s is %u.\n", "a", 'a');
printf("Character value of %s is %u.\n", "a", 'a' & 0xFF);

Remember that char and short get promoted to int as parameters.

Without the 0xFF, the character could have sign extension, if that's what
you want.  (I assumed 8-bit char.)

HTH,
--Eljay


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux