Concept

How can strlen determine the length of a C string?

ComputerScienceOne / String Library

"The standard string library provides many other convenient functions that allow you to process and modify strings. We highlight a few of the more common ones here. A full list of supported functions can be found in standard documentation.\n\nAs with regular arrays, we are responsible for ensuring that we do not access characters outside the character array of a string. Since a string is null-terminated, there is a nice function provided by the string library to determine its length:\n\nsize_t strlen(const char *s);\n\nRecall that size_t can essentially be treated as an integer, indicating the number of bytes in the passed string. Since a character is a single byte, this function tells us how many character are in the given string not including the null-terminating string. This function is an abbreviation for “string length.” Using this function we can easily iterate over each character in a string.\n\n1 int i;\n\n2 for(i=0; i<strlen(fullName); i++) {\n\n3 printf(\"fullName[%d] = %c\n\n\", i, fullName[i]);\n\n4 }"

Related Ideas

How can strlen determine the length of a C string? | ComputerScienceOne | Bifalgorithm | Bifalgorithm