Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int atoi(char* napis)
- {
- int dlugosc;
- for(dlugosc = 0; napis[dlugosc] != '\0'; ++dlugosc)
- {
- if(napis[dlugosc] < '0' || napis[dlugosc] > '9')
- return 0;
- }
- int wynik = 0;
- int mnoznik = 1;
- for(int i = 0; i < dlugosc; ++i)
- {
- wynik += (static_cast<int>(napis[dlugosc - i - 1]) - 48) * mnoznik;
- mnoznik *= 10;
- }
- return wynik;
- }
- int main()
- {
- char liczba[] = "8721353";
- cout << atoi(liczba) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement