C : Convert signed to unsigned -


actually i've (probably) "simple" problem. don't know how cast signed integer unsigned integer.

my code :

signed int entry = 0; printf("decimal number : "); scanf("%d", &entry); unsigned int uentry= (unsigned int) entry; printf("unsigned : %d\n", uentry); 

if send unsigned value console (see last code line), signed integer.

can me?

thanks lot!

kind regards, pro

printf("unsigned : %u\n", uentry); //                 ^^ 

you must use %u specifier tell printf runtime uentry unsigned int. if use %d printf function expect int, reinterpret input signed value.


Comments

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -