본문 바로가기
<프로그래밍 언어>/[C 언어]

[C 언어] strlen 함수

by 자라나는 콩 2022. 2. 28.

정의

strlen - calculate the length of a string. string 의 길이를 계산한다.

 

시놉시스

#include <cs50.h>
#include <string.h>

int strlen(string s) 

 

리턴 value

this function returns the number of characters in s, excluding the terminating NUL byte (i.e., '\0').

 

예시

#include <cs50.h>
#include <stdio.h>
#include <string.h>

int main(void)
{
    string s = get_string("Input: ");
    printf("Output: ");
    for (int i = 0, n = strlen(s); i < n; i++)
    {
        printf("%c", s[i]);
    }
    printf("\n");
}

댓글