![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Nov 2004
Posts: 2
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 4
![]() |
>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 ); |
|
|
|
|
|
#3 |
|
Newbie
Join Date: Nov 2004
Posts: 2
Rep Power: 0
![]() |
so i can use a char wherever i can use ints?
i thought with %d has to follow an int. felix |
|
|
|
|
|
#4 | |
|
Newbie
Join Date: Nov 2004
Posts: 16
Rep Power: 0
![]() |
Quote:
|
|
|
|
|
|
|
#5 |
|
Professional Programmer
Join Date: Nov 2004
Posts: 250
Rep Power: 4
![]() |
>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. |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|