Skip to content

Instantly share code, notes, and snippets.

@Learath2
Created January 20, 2017 00:22
Show Gist options
  • Save Learath2/a74968c95fcac4752a9dc1ef356480d8 to your computer and use it in GitHub Desktop.
Save Learath2/a74968c95fcac4752a9dc1ef356480d8 to your computer and use it in GitHub Desktop.
strtoi
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