### cut out digits

can anybody tell me how to cut out the middle digits of a number
eg: 255543
=23
Hi...
You should use the function itoa. After that cutting any digit is very easy.

E.g
 ``123`` ``````char str[20]; itoa(str, 356819 , 10); //str = "356819" ``````

Hope this helps (please note the code :))
Last edited on
From what I have seen itoa is outdated and is not standard C/C++.
I suggest using stringstreams instead (You will need to include sstream).

 ``12345`` ``````int x = 12345; stringstream SS; SS << x; string y = SS.str();``````

Then you can just use the erase functions from string.

http://www.cplusplus.com/reference/string/string/
http://www.cplusplus.com/reference/sstream/stringstream/
Last edited on
It's easy even without the strings library:
 ``12345678910111213`` ``````int cutMiddleDigits(int input) { int OnesDigit = input%10; int TensDigit; while (input > 0) { TensDigit = input%10; input /= 10; } return 10*TensDigit + OnesDigit; }``````
Last edited on
Topic archived. No new replies allowed.