strcpy
#include <string.h>
#include <assert.h>
char * strcpy (char *strdest, const char *STRSRC)//Adds the source string to const, indicating that it is an input parameter
{
ASSERT ((strdest! = null) && (STRSRC! = null)); Check the validity of pointers by adding a non-0 assertion to the source address and destination address
char *str = strdest;
while ((*strdest++ = * strsrc++)! = ');//The end of the loop body, the end of the strdest string is correctly added '
return str; To implement chained operations, return the destination address
}
strncpy
#include <string.h>
char * strncpy (char * dest,const char * source,int count)
{
char *start = dest;
while (Count && *dest++ =*source++)/*/copy String */
count--;
if (count)/* pad out with zeroes */
while (--count)
*dest++ = ' + ';
return (start);
}
strcmp
#include <string.h>
int strcmp (const char *str1,const char *STR2)
{
/* Do not use while (*str1++==*str2++) to compare, when not equal will still execute once + +,
The comparison value returned by return is actually the next character. The + + should be placed in the loop body. */
while (*str1 = = *STR2)
{
if (*str1 = = ' + ')
Return0;
str1++;
str2++;
}
return *STR1-*str2;
}
strncmp
Case insensitive
int strncmp (const char * s1, const char * s2, size_t len)
{
while (len--) {
if (*s1 = = 0 | | *s1! = *S2)
return *S1-*s2;
s1++;
s2++;
}
return 0;
}
Case sensitive
#include <ctype.h>
int strnicmp (const char * s1, const char * s2, size_t len)
{
Register signed Char R;
while (len--) {
if (r = ToUpper (*S1)-ToUpper (*s2)) | | *s1 = = 0)
return R;
s1++;
s2++;
}
return 0;
}
Strlen
size_t strlen_a (const char *str) {
size_t length = 0;
while (*str++)
++length;
return length;
}
size_t strlen_b (const char *str) {
const char *CP = str;
while (*cp++);
return (CP-STR-1);
}
strcpy, strncpy, strcmp, strncmp, strlen source