Home  >  Article  >  Backend Development  >  How to use strlen() function in c language

How to use strlen() function in c language

王林
王林Original
2020-07-17 11:32:208763browse

The usage of strlen() function in C language is: [strlen(const char *str)]. This function is used to calculate the length of a string up to, but not including, the null terminating character and returns the length of the string.

How to use strlen() function in c language

Function introduction:

(Recommended tutorial: c language tutorial)

strlen() Function is used to calculate the length of a string up to, but not including, the null terminating character.

Syntax structure:

size_t strlen(const char *str)

Parameter description:

  • ##str -- The string whose length is to be calculated.

Return value:

This function returns the length of the string.

Code implementation:

#include <stdio.h>
#include <string.h>
int main (){
   char str[50];
   int len;

   strcpy(str, "This is phpphp.com");

   len = strlen(str);
   printf("|%s| 的长度是 |%d|\n", str, len);
   return(0);}

Output result:

|This is phpphp.com| 的长度是 |18|

The above is the detailed content of How to use strlen() function in c language. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn