#include <stdlib.h>
#include <stdio.h>
int len(char* str)
{
int i;
i = 0;
while (str[i] != '\0')
{
i++;
}
return (i);
}
char* ft_strdup(char* src)
{
char* arr;
int i;
if(src == NULL)
return NULL;
arr = (char*)malloc(sizeof(char) * (len(src) + 1));
i = 0;
while (src[i] != '\0')
{
arr[i] = src[i];
i++;
}
arr[i] = '\0';
return (arr);
}
int main(void)
{
char c[] = "";
char *c1;
c1 = ft_strdup(c);
printf("%s", c1);
free(c1);
return 0;
}
To embed this program on your website, copy the following code and paste it into your website's HTML: