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 you determine the length of a PHP string?ComputerScienceOne · String Functions
- How do you find the length of a string and iterate over its characters?ComputerScienceOne · String Methods
- How can you create static strings with character arrays?ComputerScienceOne · Character Arrays
- How can you convert a Student structure into a string?ComputerScienceOne · To String Functions
- How can individual characters in a string be accessed safely?ComputerScienceOne · Basic Operations
- How can you create an array of strings in C?ComputerScienceOne · Arrays of Strings
- How does strcmp() compare the contents of two strings in C?ComputerScienceOne · Comparisons
- How can you compute a substring of a string?ComputerScienceOne · Arrays of Strings