Name
strlen
Synopsis
Obtains the length of a string
#include <string.h> size_tstrlen
( const char *s
);
The strlen()
function
calculates the length of the string addressed by its argument
s
. The length of a string is the number
of characters in it, not counting the terminating null character
('\0'
).
Example
char line[1024] = "This string could easily be hundreds of characters long.";
char *readptr = line;
int columns = 80;
// While the text is longer than a row:
while (strlen
( readptr ) > columns )
{ // print a row with a backslash at the end:
printf( "%.*s\\", columns-1, readptr);
readptr += columns -1;
} // Then print the rest with a newline at the end:
printf( "%s\n", readptr );
See Also
Get C in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.