#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
// long int strtol(const char *str, char **endptr, int base)
int extract_last_numbers(char *str) {
char *p = str;
while (*p) {
if (isdigit(*p) || ((*p == '-' || *p == '+') && isdigit(*(p + 1)))) {
return strtol(p, &p, 10);
} else {
p++;
}
}
return -1;
}
int main() {
char *str = "c programming 12";
printf("%d", extract_last_numbers(str));
return 0;
}
/*
run:
12
*/