C-language string processing functions

Source: Internet
Author: User

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.

 

Related Article

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.