subtract int from char array in a loop


Hello!
There is one simple thing i do not understand in the following:

char list[20]="12934225005";

int count,d1;
count=strlen(list);

for(int j=0;j<count;j++)
d1=list[j]-'0';
cout<<d1;
---------------------------------------------
As a result d1 contains 5;
What is the meaning of 5?
Ana if i do "d1=list[j] " d1 has 53.
What is 53?
Thank you very much. for your help
5 is the last character, 53 is ASCII value for '5'
each execution of loop sets d1 without incrementing it, try
1
2
3
d1=0;
for(int j=0;j<count;j++)
    d1=d1*10+list[j]-10;
closed account (48T7M4Gy)
Try this, the brackets may be the answer, depending on what you're trying to do

1
2
3
4
5
6
7
8
9
10
char list[ 20 ]="12934225005";

int count, d1;
count = strlen( list );

for( int j = 0; j < count; j++ )
{
  d1 = list[ j ] - '0';
  cout << d1;
}
Very helpful.
Thanks a lot!
Topic archived. No new replies allowed.