Funkce strlen () vypočítá délku daného řetězce.
strlen()
Funkce vezme řetězec jako argument a vrátí jeho délku. Vrácená hodnota je typu size_t
(celočíselný typ bez znaménka).
Je definován v hlavičkovém souboru.
Příklad: Funkce C strlen ()
#include #include int main() ( char a(20)="Program"; char b(20)=('P','r','o','g','r','a','m',' '); // using the %zu format specifier to print size_t printf("Length of string a = %zu ",strlen(a)); printf("Length of string b = %zu ",strlen(b)); return 0; )
Výstup
Délka řetězce a = 7 Délka řetězce b = 7
Všimněte si, že strlen()
funkce nepočítá nulový znak