字符串函数strlen

来源:互联网 发布:linux vi怎么保存 编辑:程序博客网 时间:2024/05/18 00:04

strlen是测量字符串长度的函数。函数的值为字符串中的实际的长度(不包括‘\0’在内)。

自己编写的srelen函数:

#include <stdio.h>#include <string.h>int my_strlen(char *s){    int length=0;    while(*s != '\0')    {        s++;        length++;    }    return length;}int main(){    char c[50]={0};    printf("Please input a string:");    gets(c);    printf("The length of the string is:%d\n",my_strlen(c));    return 0;}
0 0
原创粉丝点击