Use of string functions in C Language

Source: Internet
Author: User

Use of string functions in C Language
# Include
# Include
/*
Char s1 [] = "I am a student ";
Char s2 [20] = "teacher ";
Char s3 [] = "student ";
Int result;
Char s4 [20], * p;
1. String Length
Int strlen (char * str ):
Printf ("% d \ n", strlen (s1); // The length is 14
Printf ("% d \ n", strlen (s2); // The length is 7



2. Copy
Char * strcpy (char * str1, char * str2 ):
Strcpy (s4, s2); // copy s2 to s4
Printf ("% s \ n", s4); // output teacher




3. Comparison
Int strcmp (char * str1, char * str2 ):
Result = strcmp (s2, s3 );
Printf ("% d \ n", result); // s2> s3




4. Locate strings
Char * strchr (char * str, char ch );
P = strchr (s1,'s); // p points to the position of the character's in s1
Printf ("% s \ n", p); // output student




5. Search for substrings
Char * strstr (char * s1, char * s2 );
P = strstr (s1, s3); // p indicates the position of the character's in s1
Printf ("% s \ n", p); // output student




6. Connection
Char * strcat (char * str1, char * str2 ):
Strcat (s2, s3 );
Printf ("% s \ n", s2); // output teacherstudent


*/
Void ReverseName (char * name, char * newName ){


Char * p;
P = strchr (name, ''); // character location
* P = '\ 0 ';
Printf ("% s \ n", name );
Printf ("% s \ n", p );
Strcpy (newName, p + 1); // copy
Printf ("-- % s \ n", newName );
Strcat (newName, ","); // connect
Strcat (newName, name); // connection
* P = '';
Printf ("% s \ n", name );
}




Int main (){


Char name [] = "jie wang", newName [30];
ReverseName (name, newName );
Printf ("hello world \ n ");
Return 0;
}

Related Article

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.