Some functions about strings

Source: Internet
Author: User
Tags strlen

Many people think that the difficulty in the C language is pointer. Understanding the pointer is directly related to the quality of the compiled program. Therefore,
Here we list the source code of some standard functions that C compilers usually have. After reading them, we can view the pointer and string
I have some knowledge about it.
1. strlen (), calculate the string length
Int strlen (const char string)
{
Int I = 0;
While (string [I]) I ++;
Return I;
}
2. strcpy (), copy the string.
Char * strcpy (char * destination, const char * source)
{
While (* destinaton ++ = * source ++ );
Return (destination-1 );
}
3. strcat (), string connection.
Char * strcat (char * target, const char * source)
{
Char * original = target;
While (* target) target ++; // Find the end of the string
While (* target ++ = * source ++ );
Return (original );
}
4. streql () to determine whether two strings are equal.
Int streql (char * str1, char * str2)
{
While (* str1 = * str2) & (* str1 ))
{
Str1 ++;

<

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.