Basic C Language Algorithm 39-string classic operation, algorithm 39 string
// String concept!
/*
========================================================== ======================================
Question: Exercise string
1. Input and Output gets (str) puts (str)
2. Length statistics strlen (str)
3. case-sensitive conversion strupr (str) strlwr (str)
4. Compare strcmp (str1, str2)
5. Connect strcat (str1, str2)
6. Copy strcpy (str1, str2)
7. Reverse strrev (str)
========================================================== ======================================
*/
# Include <stdio. h>
# Include <string. h>
# Define gekai printf ("\ n ================================ ===============================\ n ")
Void main ()
{
Char s [256], t [256];
Printf ("string s :");
Gets (s );
Printf ("string t :");
Gets (t );
Gekai;
Printf ("\ n string s: \ n % s \ n", s );
Printf ("Length: % d \ n", strlen (s ));
Gekai;
Printf ("\ n string t is \ n % s \ n", t );
Printf ("Length: % d \ n", strlen (t ));
Gekai;
Printf ("\ n to uppercase: \ n ");
Printf ("string s :");
Puts (strupr (s ));
Printf ("string t :");
Puts (strupr (t ));
Gekai;
Printf ("\ n ");
Gekai;
Printf ("\ n to lowercase: \ n ");
Printf ("string s :");
Puts (strlwr (s ));
Printf ("string t :");
Puts (strlwr (t ));
Gekai;
Printf ("\ n ");
Gekai;
Printf ("\ n compare size :");
If (strcmp (s, t) = 1)
Printf ("string s is greater than string t! \ N ");
Else
Printf ("string s is smaller than string t! \ N ");
Gekai;
Printf ("\ n ");
Gekai;
Printf ("\ n connects two strings: \ n ");
Puts (strcat (s, t ));
Gekai;
Printf ("\ n ");
Gekai;
Printf ("\ n Copy string t to string s: \ n ");
Puts (strcpy (s, t ));
Gekai;
Printf ("\ n ");
Gekai;
Printf ("\ n reverse two strings: \ n ");
Puts (strrev (s ));
Puts (strrev (t ));
Gekai;
Printf ("\ n ");
}
/*
========================================================== ======================================
Comments: it is no problem to master the concept syntax.
========================================================== ======================================
*/
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.