#include <stdio.h>

int ft_strlen(char *str)
{
    int i;

    i = 0;
    while(str[i] != '\0')
    {
        i++;
    }
    return (i);
}


char *ft_strncat(char *dest, char *src, unsigned int nb)
{
        unsigned int dest_len;
        int i;

        i = 0;
        dest_len = ft_strlen(dest);
        
       while(i <= nb)
       {
           
           while(src[i] != '\0')
            {
                if (i == nb)
                {
                    return (dest);
                }
                else
                {
                    printf("i = %d nb = %d\n", i, nb);
                    dest[dest_len + i] = src[i];
                    dest[dest_len + i + 1] = '\0'; //Null Terminate
                }                
                i++;
            }
           
        }
        return (dest);
      
}

int main() {

    char dest[20] = "Hello, ";
    char src[] = "world!";
    int num_chars = 5; // number of characters to append
    
    printf("Before ft_strncat: %s\n", dest);
    ft_strncat(dest, src, num_chars);
    printf("After ft_strncat: %s\n", dest);

    return 0;

}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: