Home > Back-end >  Use of pointer programming, statistics, the length of the string. (do not use the string length func
Use of pointer programming, statistics, the length of the string. (do not use the string length func

Time:09-25

Using pointer programming, statistics, the length of the string, (do not use the string length function)

CodePudding user response:

 size_t MyStrLen (char * STR) 
{
If (STR==NULL)
return 0;
Char * p=STR.
While (* p!='\ 0') {
p++;
}
The return p - STR;
}

CodePudding user response:

The
reference 1/f, the truth is more important than right or wrong response:
 size_t MyStrLen (char * STR) 
{
If (STR==NULL)
return 0;
Char * p=STR.
While (* p!='\ 0') {
p++;
}
The return p - STR;
}


The following for your reference ~
 size_t my_strlen (const char * STR) 
{
If (STR==NULL)
return 0;

Const char * p=STR;

While (* p)
p++;

The return p - STR;
}

CodePudding user response:

Len=0;
While (* str++)
Len++;