Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- int ft_strlen(char *str)
- {
- int l;
- l = 0;
- while (*str++ != '\0')
- l++;
- return (l);
- }
- char *ft_strdup(char *src)
- {
- int run;
- char *str;
- run = ft_strlen(src);
- if (run == 0)
- return (0);
- str = (char*)malloc(sizeof(char) * (run + 1));
- run = 0;
- while (src[run] != '\0')
- {
- str[run] = src[run];
- run++;
- }
- str[run] = '\0';
- return (str);
- }
- #include <stdio.h>
- char *ft_strdup(char *src);
- int main()
- {
- char *f = "";
- printf("%s\n", f);
- printf("%s\n", ft_strdup(f));
- }
Advertisement
Add Comment
Please, Sign In to add comment