Friday 15 May 2015

c - Implementation of Strtol function - cast -


I have its own implementation of Stratol and it works properly, I think it will look down:

  long strotroll (const char * NPTR, four ** endpit, int base) {const char * start; Int number; Long int sum = 0; Int sign = 1; Const char * pos = nPtr; If (* position == '\ 0') returns 0; Start = pos; While (Issue (* Status)) {++ pos; } If (* pos == '-') {sign = -1; ++ status; } If (* pos == '+') ++ pos; If (base ==16 || base == 8) {if (base == 16 & amp;; pos == '0') ++ pos; If (base == 16 & amp; (* pos == 'x' || * pos == 'X')) ++ pos; If (base == 8 & pos == '0') ++ pos; } If (base == 0) {base = 10; If (* position == '0') {base = 8; ++ status; If (* position == 'x' || * position == 'x') {base = 16; ++ status; }}} If ((base>  & amp; amp; base! = 0) {errno = EINVAL; Return 0; } While (* pos! = '\ 0') {number = -1; If ((int) * pos> = 48 & amp; amp; (int) * pos & lt; = 57) {number = (int) * pos - 48; } If (ISLF (* status)) {number = (to) top (* position) - 55; } If (number & lt; base & amp; number! = -1) {if (sign == -1) {if (sum> = ((LONG_MIN + number) / base) sum = sum * base - Number; Else {errno = ERANGE; Yoga = LONG_MIN; }} And {if (yoga & lt; = ((long_max - number) / base) sum = sum * base + number; Else {errno = ERANGE; Yoga = LONG_MAX; 2} 'X')) {--pos; break; } And break; ++ status; } If (! ISDiGit (* (Pause-1)) and alpha (* (pause-1)) pause = start; If (endpt) * and pt = (four *) pauses; Refund Amount; }   

Although I have a question about the last line:

  * endPtr = (four *) pos;   

Why do I have to reject the poles (ARA), and PTR and pause both points of the camera, in the second case the warning states: Assignment creates an integer notation with an integer . Thanks for the help

Because they are not of the same type

Type * endPtr is four * type

pos const char * .

No comments:

Post a Comment