Previous Page
Next Page

strlen

Obtains the length of a string

#include <string.h>
size_t strlen ( 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

wcslen( )


Previous Page
Next Page