Question: If I got `char* "12345"` and I want to convert to `int` with a recursive function, how can I do that ?

This is a simple way how to convert `char` to `int` with loop.

```
while (str[i]) {
    new_num *= 10;
    new_num += str[i++] - '0';
}

```

Answer: 
Yet another variant without length calculation:

```
#include <stdio.h>
int convert_(char* s, int r) {
  return *s ? convert_(s + 1, r * 10 + (*s - '0')) : r;
}
int convert(char* s) {
  return convert_(s, 0);
}
void main()
{
  printf("%d", convert("123456"));
}

```
I just tried with only one function to convert string to integer may be helpful,

```
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int strtoint(char *ptr)
{
    int num;
    char *str = NULL;
    if(strlen(ptr) == 0)
        return 0;
    else if(strlen(ptr) == 1)
        return ptr[strlen(ptr)-1]-48;
    else
    {
        str = (char *) malloc(strlen(ptr)-1);
        strcpy(str,ptr);
        str[strlen(ptr)-1]='\0';
        num = (strtoint(str) * 10) + ptr[strlen(ptr)-1]-48;
        free(str);
        return num;
    }
}
int main(void)
{
    printf("converted string %d\n",strtoint("12345"));
}

```