Guest User

Untitled

a guest
Jan 21st, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. unsigned long int getNumber(TParams *pParams)
  2. {
  3.     unsigned long int cislo = 0;/** inicializacia návratového čisla z funkcie */
  4.  
  5.     while (true)
  6.     {
  7.         char c = getchar();
  8.  
  9.         if (c == ' ')
  10.             continue;
  11.         if (c == '\n' || c == EOF)
  12.             break;
  13.  
  14.         if (c < '0' || c > '9')
  15.         {
  16.             pParams->ecode = EVALUE;
  17.             return 0;
  18.         }
  19.  
  20.         if (cislo > ULONG_MAX / 10 || ((cislo == ULONG_MAX / 10) &&
  21.         ((unsigned long int)(c - '0') > (ULONG_MAX - (ULONG_MAX / 10) * 10))))
  22.         {
  23.             pParams->ecode = EOVERFLOW;
  24.             return 0;
  25.         }
  26.  
  27.         cislo = cislo * 10 + c - '0';
  28.     }
  29.  
  30.     return cislo;
  31. }
Add Comment
Please, Sign In to add comment