String manipulation functions and re-assignment problems

Source: Internet
Author: User

1, for char* or char[] defined string, often have splicing, interception, replication and a series of operations. Specific functions can refer to the online reference. It is worth noting that the original functions were discarded after vs2013, and the functions were redefined in a function_s way, increasing the control over the size of the data and preventing overflow.

For example:

Original--strcat (char* dest,char* src)

Now--strcat_s (char* dest,sizeof (dest), char* src)

2, there is one notable problem that always makes mistakes is the re-assignment of strings.

For strings (no matter what type, here is a char example)

For example:

Char b[]= "234"; //This is possible, is the initialization of the assignment

However, the re-assignment is not allowed,

For example b= "567"; Error! Because B is the first address of the array, the system allocates memory to him as "234", which is a pointer constant and cannot be re-assigned.

Need to adopt:

The 1,strcpy_s function, strcpy_s (s, 200, "234"), where S is best represented as char [], facilitates the definition of buffer size.

2, Will char[]-->char*

String manipulation functions and re-assignment problems

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.