12,758,323 members (33,130 online)
Rate this:
See more:
Hi my friends .
pleas give me a solution about converting int to char and convert char to int in win32 project
Thank you .
Posted 17-Sep-12 20:14pm
Updated 18-Sep-12 0:36am
Malli_S29.6K
v3

Rate this:

Solution 1

Аslam Iqbal 18-Sep-12 2:06am

nice
Rate this:

Solution 2

Give a example.
char ch = '0';
int n = ch - 48;
Than value of n is 0.
48 is the distance in ASCII table.
Richard MacCutchan 18-Sep-12 10:24am

Why not `int n = ch - '0';`, which is at least obvious?
Joneeky 18-Sep-12 10:30am

Yes,You also can do this. But I am used to use 48.
Richard MacCutchan 18-Sep-12 10:43am

It's about readability, '0' means something useful to a new person looking at the code, 48 does not.
Joneeky 18-Sep-12 10:48am

Okey,maybe you are right.
Richard MacCutchan 18-Sep-12 11:55am

Well think about it. In the first line of your example you represent the value of the zero character by '0', which is quite clear. In the next line you represent the exact same value by the integer 48, and it is not immediately obvious where that value comes from. Somewhat inconsistent don't you think?
Joneeky 19-Sep-12 1:01am

OK, I have learnt.

Top Experts
Last 24hrsThis month
 Graeme_Grant 376 Bryian Tan 195 Richard Deeming 170 Maciej Los 120 OriginalGriff 118
 OriginalGriff 4,277 Peter Leow 3,249 Karthik Bangalore 2,574 ppolymorphe 2,559 Graeme_Grant 2,352