Functions to handle big numbers in C I'm working to implement some simple bigint functions for addition, multiplication and powers. They work correctly but the larger the numbers the longer the time it takes.
For example 210000 takes a very long time.
Here are all the functions I'm using.

char    *ft_strnew(size_t size)
    {
    char    *temp;
    size_t  i;

    if (!(temp = (char*)malloc(sizeof(char) * (size + 1))))
        return (NULL);
    i = 0;
    while (i &lt; size)
    {
        temp[i] = '\0';
        i++;
    }
    temp[i] = '\0';
    return (temp);
}

char    *ft_strjoin(char const *s1, char const *s2)
{
    char    *temp;
    int     i;
    int     j;

    if (!(temp = (char*)malloc(sizeof(char) *
        (ft_strlen(s1) + ft_strlen(s2) + 1))))
        return (NULL);
    i = 0;
    j = 0;
    while (s1[i])
    {
        temp[j] = s1[i];
        i++;
        j++;
    }
    i = 0;
    while (s2[i])
    {
        temp[j] = s2[i];
        i++;
        j++;
    }
    temp[j] = '\0';
    return (temp);
}

int         left_one(int *i, char c)
{
    if (--(*i) &lt; 0)
        return (0);
    else
        return (c - '0');
}

char        *add_char(char *nbr1, char *nbr2)
{
    int     i;
    int     j;
    int     left[4];
    char    *temp;

    left[0] = 0;
    temp = ft_strnew(0);
    i = ft_strlen(nbr1);
    j = ft_strlen(nbr2);
    if (i &gt; j)
        left[3] = i;
    else
        left[3] = j;
    while (--left[3] &gt;= 0)
    {
        left[1] = left_one(&amp;i, nbr1[i - 1]);
        left[2] = left_one(&amp;j, nbr2[j - 1]);
        left[0] += left[1] + left[2];
        temp = ft_charjoin((left[0] % 10) + '0', temp, 'l');
        left[0] /= 10;
    }
    if (left[0] &gt; 0)
        temp = ft_charjoin((left[0] % 10) + '0', temp, 'l');
    return (temp);
}

char        *multi1_char(char *nbr1, int nbr2)
{
    int     i;
    char    *temp;

    if (nbr1[0] == '0' || nbr2 == 0)
        return ("0");
    i = -1;
    temp = ft_strdup(nbr1);
    while (++i &lt; nbr2 - 1)
        temp = add_char(temp, nbr1);
    return (temp);
}

char        *multi_char(char *nbr1, char *nbr2)
{
    int         i;
    char        *temp;
    int         j;
    char        *temp1;
    int         t;
    char        *mul;

    mul = ft_strnew(0);
    temp = ft_strnew(1);
    j = 0;
    i = ft_strlen(nbr2);
    while (--i &gt;= 0)
    {
        t = -1;
        temp1 = multi1_char(nbr1, nbr2[i] - '0');
        //temp1 = multi1_char(temp1, 10*j);
        /*while (++t &lt; j)
            temp1 = ft_strjoin(temp1, "0");*/
        temp1 = ft_strjoin(temp1, mul);
        temp = add_char(temp, temp1);
        mul = ft_strjoin("0", mul);
        j++;
    }
    return (temp);
}

char    *power_char(int nbr1, int nbr2)
{
    char        *temp;

    temp = ft_strnew(0);
    if (nbr2 == 1)
        return (ft_itoa(nbr1));
    if (nbr2 % 2 == 0)
    {
        temp = power_char(nbr1, nbr2 / 2);
        return (multi_char(temp, temp));
    }
    else
    {
        nbr2 -= 1;
        temp = power_char(nbr1, nbr2 / 2);
        return(multi_char(ft_itoa(nbr1), multi_char(temp, temp)));
    }
}


I came up with a way to make the function that handles powers work faster but still the multiplication function is slow for big numbers.

Is there any way of improving my functions or are they bad from the start and I should start all over?
It seems you're allergic to for loops for some reason; for example, in ft_strnew:

for (size_t i = 0; i &lt; size; i++)


There are examples elsewhere.

Don't predeclare your variables, e.g.

int     i;
int     j;


This hasn't been needed for 20 years. Declare them where they're used.

Replace this entire loop:

size_t  i;
i = 0;
while (i &lt; size)
{
    temp[i] = '\0';
    i++;
}
temp[i] = '\0';


With this:

memset(temp, '\0', size+1);


Otherwise, your entire approach to arbitrary-size integer math is a quite slow one. (Other libraries have solved this, but it's nice that you're trying to learn.) You can't be doing this character by character; rather you need to do it integer by integer. Do some googling about arbitrary-precision integer arithmetic on 64-bit architectures.

A comment on something you said:


  They work correctly but the larger the numbers the longer the time it takes.


No arbitrary-precision library can escape this. The execution time of even the best libraries will scale according to the size of the input when it exceeds the size of the machine word.