strlen.c 467 B

12345678910111213141516171819202122232425262728
  1. /* Assignment name : ft_strlen
  2. Expected files : ft_strlen.c
  3. Allowed functions:
  4. --------------------------------------------------------------------------------
  5. Write a function that returns the length of a string.
  6. Your function must be declared as follows:
  7. int ft_strlen(char *str); */
  8. #include <stdio.h>
  9. int ft_strlen(char *str)
  10. {
  11. int i;
  12. i = 0;
  13. while (str[i] != '\0')
  14. i++;
  15. return (i);
  16. }
  17. int main(void)
  18. {
  19. printf("%d\n", ft_strlen("Hello World"));
  20. }