C-language string processing functions
Introduction to string processing functions in C Language
The following describes eight basic common string processing functions, which are often used in numeric arrays (some functions ). These functions are generally provided in all C language compiling systems.
1,Puts Function-- Output string functions
The general format is puts (string group)
Purpose: Output a string to the terminal. For example, char is a string and the initial value is assigned. Call puts (string); to output the string.
2,Gets Function-- Input string Function
General Format: gets (character array)
Purpose: input a string to the character array from the terminal and obtain a function value to become the starting address of the character array.
Gets (str );
Keyboard Input, you know.
Note: The puts and gets functions can only output or input one string.
3,Strcat Functions-- String connection Function
General Format: strcat (character array 1, character array 2 );
Purpose: connect the strings in two string arrays and connect string 2 to the end of string 1.
Note: The character array 1 must be large enough to accommodate the connected New String.
4,Strcpy/strncpy Function-- String copy Function
General Format: strcpy (character array 1, string 2 );
Purpose: Copy string 2 to character array 1.
For example, char str1 [10], str2 [] = "DongTeng ";
Strcpy (str1, str2 );
The execution result is: you understand
Note: 1. You cannot directly assign a String constant or character array to a character array using a value assignment statement.
2. Use strncpy to assign values to characters at the specified position. Strncpy (str1, str2, 3); copies the 3rd characters in str2 to str1.
5,Strcmp Functions-- String comparison Function
General Format: strcmp (string 1, string 2 );
Purpose: Compare the differences between two strings. There are different comparison rules.
6,Strlen Function-- Test the function of String Length.
General Format: strlen (character array );
For example, char str [10] = "DongTeng ";
Printf ("% d", strlen (str ));
The result is as follows: 5
7,Strlwr Function-- Converts the string to lowercase.
General Format: strlwr (string );
8,Strupr Function-- Convert to an upper-case Function
General Format: strupr (string ).
The above is just a simple common function in C language. I hope you can correct the shortcomings.