Created
January 20, 2017 00:22
-
-
Save Learath2/a74968c95fcac4752a9dc1ef356480d8 to your computer and use it in GitHub Desktop.
strtoi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int strtoi(const char *nptr, char **endptr, int base) | |
{ | |
long n = strtol(nptr, endptr, base); | |
if(n > INT_MAX){ | |
errno = ERANGE; | |
return INT_MAX; | |
} | |
else if(n < INT_MIN){ | |
errno = ERANGE; | |
return INT_MIN; | |
} | |
return n; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment