#include #include #include int *strtoint(char *in, size_t start, size_t n) { int *ret = malloc(sizeof(int)); *ret = 0; int offset = start + n - 1; if (offset < 0) { return NULL; } for (int i = 0; i < n; i++) { int position = offset - i; printf("foo: %c\n", in[position]); if (in[position] >= '0' && in[position] <= '9') { *ret += (in[position] - '0') * pow(10, i); } else { return NULL; } } return ret; } int main() { char *in = "abcd123"; int *ret = strtoint(in, 4, 3); if (ret != NULL) { printf("%s | %d\n", in, *ret); } else { printf("ret is NULL\n"); } }