ft_strlen

one·2021년 1월 5일
0

✅strlen

  • calculate the length of a string
  • The strlen() function calculates the length of the string pointed
    to by s, excluding the terminating null byte `('\0').

💾함수 원형

size_t strlen(const char *s);

💻Parameter

  • s : 문자열

💻Return value

  • 문자열의 길이(타입은 size_t)

💾함수 구현

size_t  ft_strlen(const char* s)
{
    size_t i;

    i = 0;
    while (s[i] != '\0')
        i++;
    return (i);
}

💾사용 예시

#include <stdio.h>

void main()
{
    char str1[20] = "Hello";
    char str2[30] = "Worl\0d!!";

    printf("str1 len : %d\n", ft_strlen(str1));
    printf("str2 len : %d\n", ft_strlen(str2));

    return (0);
}

profile
늘 호기심을 갖고, 새로운 것에 도전할 것.

0개의 댓글