You are here

String length using strlen

C program to find string length using strlen function of "string.h" header file.

Function strlen is used to find length of a string.

Declaration: int strlen(char*);

C programming code for strlen

  1. #include <string.h>
  2.  
  3. int main()
  4. {
  5.    char s[] = "C program";
  6.    int length;
  7.    
  8.    length = strlen(s);
  9.    
  10.    printf("Length of the string \"%s\" = %d", s, length);
  11.    
  12.    return 0;
  13. }

Output of the program:
Length of the string "C program" = 9