strcopy.c 624 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /* Assignment name : ft_strcpy
  2. Expected files : ft_strcpy.c
  3. Allowed functions:
  4. --------------------------------------------------------------------------------
  5. Reproduce the behavior of the function strcpy (man strcpy).
  6. Your function must be declared as follows:
  7. char *ft_strcpy(char *s1, char *s2); */
  8. #include <stdio.h>
  9. #include <string.h>
  10. char *ft_strcpy(char *s1, char *s2)
  11. {
  12. int i;
  13. i = 0;
  14. while (*(s2 + i))
  15. {
  16. s1[i] = s2[i];
  17. i++;
  18. }
  19. s1[i] = '\0';
  20. return (s1);
  21. }
  22. int main(void)
  23. {
  24. char s1[] = "TTTT";
  25. char s2[] = "YYYY";
  26. printf("%s\n", strcpy(s1, s2));
  27. printf("%s\n", ft_strcpy(s1, s2));
  28. }