C Language String processing function

Source: Internet
Author: User

Introduction to string processing functions in C language

Here are 8 basic common string handling functions, often used in numeric arrays (partial functions). These functions are generally available 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 --function of input string

General form: gets (character array)

Function: Enter a string from the terminal into a character array, and get a function value that becomes 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);

Function: Concatenate strings in two string arrays and concatenate string 2 to the back of string 1.

Description: The character array 1 must be large enough to accommodate 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

Note: 1. You cannot directly assign a string constant or a character array directly to an array of characters using an assignment statement.

2. Use strncpy to assign a value to the specified position of the character. strncpy (str1,str2,3); copies the 3rd character in str2 to str1.

5.strcmp function --string comparison function

General form: strcmp (String 1, string 2);

function: Used to compare the differences of two strings. have different rules for comparison.

6.strlen function --function of measuring string length

General form: strlen (character array);

such as: Char str[10]= "Dongteng";

printf ("%d", strlen (str));

The result is: 5

7.strlwr function --function converted to lowercase

General form: STRLWR (String);

8.STRUPR function --the function converted to uppercase

General form: STRUPR (String).

The above is just a simple C language commonly used functions, the shortcomings of the point of looking.

C Language String processing function

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.