>>985221Good, concise answer, although it's a bit opaque for a beginner, and if you pass the length as a parameter you get away with it in O(n), rather than O(Σ(n to 1)) = O(n^2) with successive calls to strlen.
>>985183Here's an example of how you would approach it. You should be able to fill in the blanks with the hints provided.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int strtoint(const char *c, int place) {
if(!*c) //Base Case: Hit the null terminator at the end of the string
return /*some value*/; //(Hint: Should we count a non-digit?)
int digit = //Turn the current character = (*c) into a digit
//(Hint 1:
https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/ASCII-Table.svg/738px-ASCII-Table.svg.png)
//(Hint 2: The digit characters are sequential, as are digits.
int power = //Calculate the power of 10
//(Hint:
http://www.cplusplus.com/reference/cmath/)
int rest = strtoint(/*Recursive call to the rest of the string*/);
//(Hint: One position further in the string, one less power of ten)
return (digit * power) + rest;
}
int main() {
char *str = "29153"; //Length: 5, first digit = 2 * 10^4
int res = strtoint(str, strlen(str)-1);
printf("String: %s, Integer: %d\n", str, res);
return EXIT_SUCCESS;
}