Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int GetLength(char* str) // ['m','a','r','i','a','m','i','\0']
- {
- int i = 0;
- int counter = 0;
- while (str[i] != '\0')
- {
- counter++;
- i++;
- }
- return counter;
- }
- int stringToInt(char* str)
- {
- int length = GetLength(str);
- int result = 0;
- //540
- for (int i = 0; i < length; i++)
- {
- result = result * 10 + (str[i] - '0'); // '0' = 48
- }
- return result;
- }
- int main()
- {
- char Array[] = {"14955"};
- int res = stringToInt(Array);
- cout << res;
- cin.get();
- cin.get();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement