December 2005
Beginner to intermediate
618 pages
20h 19m
English
strlen
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').
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 );Read now
Unlock full access