How to use strlen() function in c language

王林
Release: 2020-07-17 11:32:20
Original
8756 people have browsed it

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)
Copy after login

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);}
Copy after login

Output result:

|This is phpphp.com| 的长度是 |18|
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!