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;
}