Advertisement
MeehoweCK

Untitled

Jun 19th, 2019
208
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int atoi(char* napis)
  6. {
  7.     int dlugosc;
  8.     for(dlugosc = 0; napis[dlugosc] != '\0'; ++dlugosc)
  9.     {
  10.         if(napis[dlugosc] < '0' || napis[dlugosc] > '9')
  11.             return 0;
  12.     }
  13.     int wynik = 0;
  14.     int mnoznik = 1;
  15.  
  16.     for(int i = 0; i < dlugosc; ++i)
  17.     {
  18.         wynik += (static_cast<int>(napis[dlugosc - i - 1]) - 48) * mnoznik;
  19.         mnoznik *= 10;
  20.     }
  21.     return wynik;
  22. }
  23.  
  24. int main()
  25. {
  26.     char liczba[] = "8721353";
  27.     cout << atoi(liczba) << endl;
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement