Skip to content

Commit 90e9d15

Browse files
committed
Add documentation for strlen function in String Manipulation API
1 parent 647420b commit 90e9d15

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

doc/contents/string.tex

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,34 @@ \subsection*{Examples}
3737
In the future, we could returning the difference between the first differing
3838
characters, which would allow for more detailed comparisons. This would enable
3939
users 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}

0 commit comments

Comments
 (0)