Can one optimize/make it shorter?

A simple code made for training, usless in way its right now. It converts 4 numbers from char[] and change it into ints.
I'm asking you to see what could be done better and what I fucked up : *
Input: 1 2 3 4
Output 1 2 3 4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <iostream>
#include <math.h>
int Xa,Xb,Ya,Yb,Which;
char Chars1[25],Chars2[25];
using namespace std;
int main(){
cin.getline(Chars1, 25);
for(int a=0,b=0;a<25;a++)
{
	if(int(Chars1[a])>=48 && int(Chars1[a])<=57)	
	{
	Chars2[b]=Chars1[a];
	b++;
	}
	if(b!=0 && (int(Chars1[a])<48 || int(Chars1[a])>57))
	{
	Which++;
	switch(Which)
		{
		case 1:
		{
			for(int c=b-1,d=0;c>=0;c--,d++)
			{			
			Xa+=(int(Chars2[c])-48)*pow(10,d);
			}
			b=0;
			break;
		}
		case 2:
		{
			for(int c=b-1,d=0;c>=0;c--,d++)
			{			
			Xb+=(int(Chars2[c])-48)*pow(10,d);
			}
			b=0;		
			break;
		}
		case 3:
		{
			for(int c=b-1,d=0;c>=0;c--,d++)
			{			
			Ya+=(int(Chars2[c])-48)*pow(10,d);
			}
			b=0;		
			break;
		}
		case 4:
		{
			for(int c=b-1,d=0;c>=0;c--,d++)
			{			
			Yb+=(int(Chars2[c])-48)*pow(10,d);
			}
			b=0;		
			break;
		}
		default: {b=0;break;}
		
	}
	}
}
cout << Xa << " " << Xb << " " << Ya << " " << Yb << "\n"; 
}

You are thinking too hard.
Or not hard enough...

It doesn't matter how many digits you have. Start with the first in your list and work your way to the end. Pseudocode:
1
2
3
4
5
6
7
8
9
10
int string_to_int( const char* string )
{
  int result = 0;
  for each digit in string
  {
    result *= 10;
    result += value of digit;
  }
  return result;
}
Right, creating function makes everything easier
But I don't understand that part, or just you don't :*
1
2
    result *= 10;
    result += value of digit;

in number like 123
i have to: 1*10^2+2*10^1+1*10^0
so basicly
result+=(int(Chars2[c])-48)*pow(10,d);
: )
But yeah, function makes everything easier
You can only deal with one digit at a time.

result = 0
"425" --> result = (result * 10) + 4
"25" --> result = (result * 10) + 2
"5" --> result = (result * 10) + 5
Topic archived. No new replies allowed.