![]() |
hi,
i am trying to read one byte of data from a FILE* like this. int a = fread((void *)(&(col.r)), sizeof(char), 1, f_origin); where col.r is a char. fread returns 1, so i suppose the data is read correctly into col.r 1. is this cast to (void *) necessary? could i just write int a = fread((&(col.r)), sizeof(char), 1, f_origin); ? 2. i am struggling to find an appropriate call to printf to display the char value, for example in hexadecimal or integer. this should be easy.. thanks for your kind answers. |
>1. is this cast to (void *) necessary?
No. >2. i am struggling to find an appropriate call to printf to display the char value, for example in hexadecimal or integer. :
printf ( "Decimal: %d\nOctal: %o\nHexadecimal: %x\n", col.r, col.r, col.r ); |
so i can use a char wherever i can use ints?
i thought with %d has to follow an int. felix |
Quote:
|
>so i can use a char wherever i can use ints?
>i thought with %d has to follow an int. char is an integral type with a safe conversion to int. The inverse may not be safe, so be careful when treating int like char. >No, if you use %d with a char you get the ascii-value. You get the integral value. Not all systems use ASCII. |
| All times are GMT -5. The time now is 2:33 AM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC