1. strcat
[Cpp]
Char * strcat (char * strDest, const char * strScr) // Add the source string to const, indicating that it is an input parameter
{
Char * address = strDest; // if this statement is placed after assert, a compilation error occurs.
Assert (strDest! = NULL) & (strScr! = NULL); // Add non-0 assertions to the source and target addresses
While (* strDest) // is while (* strDest! = '\ 0') Simplified Form
{// If while (* strDest ++) is used, an error occurs because ++ is not subject to loops.
StrDest ++; // restricted. Therefore, it must be in the body of the loop ++; because if * strDest refers
} // End sign '\ 0' to the string '.
While (* strDest ++ = * strScr ++) // while (* strDest ++ = * strScr ++ )! = '\ 0') Simplified Form
{
NULL; // you can use ++ in this loop condition,
} // The statement * strDest = '\ 0' can be added here. Is it necessary?
Return address; // return the destination address for chained operations
}
Char * strcat (char * strDest, const char * strScr) // Add the source string to const, indicating that it is an input parameter
{
Char * address = strDest; // if this statement is placed after assert, a compilation error occurs.
Assert (strDest! = NULL) & (strScr! = NULL); // Add non-0 assertions to the source and target addresses
While (* strDest) // is while (* strDest! = '\ 0') Simplified Form
{// If while (* strDest ++) is used, an error occurs because ++ is not subject to loops.
StrDest ++; // restricted. Therefore, it must be in the body of the loop ++; because if * strDest refers
} // End sign '\ 0' to the string '.
While (* strDest ++ = * strScr ++) // while (* strDest ++ = * strScr ++ )! = '\ 0') Simplified Form
{
NULL; // you can use ++ in this loop condition,
} // The statement * strDest = '\ 0' can be added here. Is it necessary?
Return address; // return the destination address for chained operations
}
2. strcmp
[Cpp]
Int _ cdecl strcmp (
Const char * src,
Const char * dst
)
{
Int ret = 0;
While (! (Ret = * (unsigned char *) src-* (unsigned char *) dst) & * dst)
++ Src, ++ dst;
If (ret <0)
Ret =-1;
Else if (ret> 0)
Ret = 1;
Return (ret );
}
Int _ cdecl strcmp (
Const char * src,
Const char * dst
)
{
Int ret = 0;
While (! (Ret = * (unsigned char *) src-* (unsigned char *) dst) & * dst)
++ Src, ++ dst;
If (ret <0)
Ret =-1;
Else if (ret> 0)
Ret = 1;
Return (ret );
}
[Cpp]
Int strcmp (const char * dest, const char * source)
{
Assert (NULL! = Dest) & (NULL! = Source ));
While (* dest & * source & (* dest = * source ))
{
Dest ++;
Source ++;
}
Return * dest-* source;
/* If dest> source, the return value is greater than 0. If dest = source, the return value is equal to 0. If dest <source, the return value is less than 0. */
}
Int strcmp (const char * dest, const char * source)
{
Assert (NULL! = Dest) & (NULL! = Source ));
While (* dest & * source & (* dest = * source ))
{
Dest ++;
Source ++;
}
Return * dest-* source;
/* If dest> source, the return value is greater than 0. If dest = source, the return value is equal to 0. If dest <source, the return value is less than 0. */
}
3. strcpy
[Cpp]
Char * strcpy (char * strDestination, const char * strSource)
{
Assert (strDestination! = NULL & strSource! = NULL );
Char * strD = strDestination;
While (* strD ++ = * strSource ++ )! = '\ 0 ');
Return strDestination;
}
Char * strcpy (char * strDestination, const char * strSource)
{
Assert (strDestination! = NULL & strSource! = NULL );
Char * strD = strDestination;
While (* strD ++ = * strSource ++ )! = '\ 0 ');
Return strDestination;
}
4. strncmp
[Cpp]
Char * strncpy (char * dest, const char * src, size_t count)
{
Char * tmp = dest;
Assert (src! = NULL & dest! = NULL );
While (count ){
If (* tmp = * src )! = 0)
Src ++;
Tmp ++;
Count --;
}
Return dest;
}
Char * strncpy (char * dest, const char * src, size_t count)
{
Char * tmp = dest;
Assert (src! = NULL & dest! = NULL );
While (count ){
If (* tmp = * src )! = 0)
Src ++;
Tmp ++;
Count --;
}
Return dest;
}
5. strrchr
[Cpp]
Char *
Strrchr (const char * s, int c)
{
Register const char * found, * p;
C = (unsigned char) c;
/* Since strchr is fast, we use it rather than the obvious loop .*/
If (c = '\ 0 ')
Return strchr (s, '\ 0 ');
Found = NULL;
While (p = strchr (s, c ))! = NULL)
{
Found = p;
S = p + 1;
}
Return (char *) found;
}
Char *
Strrchr (const char * s, int c)
{
Register const char * found, * p;
C = (unsigned char) c;
/* Since strchr is fast, we use it rather than the obvious loop .*/
If (c = '\ 0 ')
Return strchr (s, '\ 0 ');
Found = NULL;
While (p = strchr (s, c ))! = NULL)
{
Found = p;
S = p + 1;
}
Return (char *) found;
}