Strings in the C language

Source: Internet
Author: User
Tags first string

1. Conceptually, there is no string data type in the C language

2. Using character arrays in the C language to simulate strings

The string in the 3.C language is an array of characters ending with '% '

Strings in the 4.C language can be allocated to stack space, heap space, or read-only storage

5. The length of the string is the number of characters contained in the string

The length of the string in the 6.C language refers to the number of characters that appear before the first ' + ' character

The length of the string is determined in the 7.C language by the '% ' Terminator

Attention:

The number of strlen returned is unsigned, and the two unsigned number subtraction remains an unsigned number.

1. In general, do not write your own C label library has been provided by the function

2. The standard library is sometimes implemented in assembly language in order to make full use of the special instructions provided by the machine in pursuit of maximum speed.

3. Reusing an existing library of functions is more efficient.

4. An unrestricted string function is to determine the length by looking for the string "Terminator"

5.strncpy and Strncat must ensure that the remaining space in the target character array is sufficient to hold the entire source string.

6.STRCMP with a value of 0 means two strings equal, the first string is greater than the second string when the return value is greater than 0, the first string is less than the second string when the return value is less than 0

The 7.STRCNMP does not modify the parameter values, but still takes '% ' as the Terminator.

8. Length-constrained string function receives a displayed length parameter to limit the number of characters in the operation

9.strncpy copies only Len characters to the target string, and when the source string is less than Len, the remaining space is filled with ' \ s ', and when the source string is longer than Len, only Len characters are copied, and he will not end with '. '

10.strncat copy len characters from the source string up to the target string, strncat always adds '% ' after the end string, and Strncat does not fill the remaining space in the target string with '/'.

11.STRNCMP compares only Len characters for equality.

Strings in the C language

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.