#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>

char *ft_strdup(char *src)
{
    int  i = 0;
    char *dup;

    while(src[i] != '\0')
        i++;

    dup = (char *)malloc(sizeof(char) * (i+1));

    if(dup == NULL)
        return NULL;

    i = 0;
    while(src[i]){
        dup[i] = src[i];
        i++;
    }
    dup[i] = '\0';

    return dup;
}

int main()
{
    char *str = "hello world";
    char *newstr;


    newstr = ft_strdup(str);
    printf("%s", newstr);

    free(newstr);

    return 0;
}

Embed on website

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