Here are 8 basic common string-handling functions that are often used in numeric arrays (partial functions). These functions are generally provided in all C-language compilation systems.
1,puts function --function of output string
The general form is puts (string group)
Function: Outputs a string to the terminal. For example, char a string and give the initial value. Call puts (string), and the output of the string.
2,gets function --the function of the input string
General form: gets (character array)
Function: Enter a string from the terminal to the character array, and get 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 enter a string.
3,strcat function --string connection function
General form: strcat (character array 1, character array 2);
Role: Concatenate strings in two string arrays and concatenate string 2 to the back of string 1.
Description: Character array 1 must be large enough to hold the new string after the connection.
4,strcpy/strncpy function --string copy function
General form: strcpy (character array 1, string 2);
Function: Copy the string 2 to the character array 1.
such as: Char str1[10],str2[]= "Dongteng";
strcpy (STR1,STR2);
The result after execution is: you know
Attention:
1. An assignment statement cannot be used directly to give a string constant or an array of characters directly to an array of characters.
2. A character that can assign a value to a specified position with strncpy. strncpy (str1,str2,3); copies the 3rd character in the str2 to str1.
5,strcmp function --string comparison function
General form: strcmp (String 1, string 2);
Role: Used to compare the differences between two strings. have different comparison rules.
6,strlen function --the function of measuring string length
General form: strlen (character array);
such as: Char str[10]= "Dongteng";
printf ("%d", strlen (str));
The results obtained are: 5
7,strlwr function --Convert to lowercase functions
General form: STRLWR (String);
8,STRUPR function --converted to uppercase function
General form: STRUPR (String).
The above is just simple C language commonly used functions, deficiencies also look at.
The above article on the C language string processing function is a small series to share all the content, hope to give you a reference, but also hope that we support the cloud habitat community.