Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.47 KB | None | 0 0
  1. double from_str_to_double(const char s[125]) {
  2.     if (s[0] == '-') {
  3.         printf("%s", "It's a SHOP!!! Should be positive! EVERETHING\n");
  4.         return -1;
  5.     }
  6.     int i = 0, sum = 0;
  7.     while (s[i] != '\0') {
  8.         if (s[i] <= '9' && s[i] >= '0' && sum < INT_MAX / 100) {
  9.             sum = sum * 10 + (s[i] - '0');
  10.             i++;
  11.         } else {
  12.             printf("%s", "Should be NUMBER!\n");
  13.             return -1;
  14.         }
  15.     }
  16.     return sum;
  17. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement