File tree Expand file tree Collapse file tree 1 file changed +31
-1
lines changed
Expand file tree Collapse file tree 1 file changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -37,4 +37,34 @@ \subsection*{Examples}
3737In the future, we could returning the difference between the first differing
3838characters, which would allow for more detailed comparisons. This would enable
3939users to understand how far apart the strings are in terms of character values.
40- \end {note }
40+ \end {note }
41+
42+ \subsection {\texttt {strlen(const char *str) } }
43+
44+ \paragraph {Purpose }
45+ Calculates the length of a null-terminated string.
46+
47+ \paragraph {Overview }
48+ This function counts the number of characters in a null-terminated string,
49+ excluding the null terminator itself. It returns the length of the string as an
50+ unsigned integer.
51+
52+ \paragraph {Return Values }
53+ \begin {itemize }
54+ \item The number of characters in the string, not including the null terminator.
55+ \item 0 if the string is empty (i.e., the first character is the null terminator).
56+ \end {itemize }
57+
58+ \paragraph {Behavior }
59+ The function iterates through the input string until the null terminator is found, returning
60+ the number of characters preceding it. If the input pointer is not a valid
61+ null-terminated string, the behavior is undefined.
62+
63+ \subsection* {Examples }
64+ \ begin{lstlisting} [language=C, caption=String Length Example]
65+ size_t result = strlen("abc"); // Expect 3
66+ printf("Expect len 3 -> %d\n", result);
67+
68+ result = strlen(""); // Expect 0
69+ printf("Expect len 0 -> %d\n", result);
70+ \end {lstlisting }
You can’t perform that action at this time.
0 commit comments