String copy function strcpy notation _ go

Source: Internet
Author: User

Code highlighting produced by Actipro Codehighlighter (freeware) http://www.codehighlighter.com/-->//CppReference.cpp: Defines the entry point of the console application. //#include"stdafx.h"using namespacestd;/** Description: String copy version 1 * Parameters: dest Destination Address, SRC Source address * Return: Return copy good address, if error or overlap, undefined * Exception: There may be a string overflow, and dest occupies less space than SRC. */Char*STRCPY_V1 (Char*dest,Const Char*src) {    //when debugging, use assertions, ingress detectionASSERT ((dest!=null) && (src!=NULL)); //Note that the memory here points to the memory where the parameter dest resides, not the stack memory, so it can be returned in the function    Char*to =dest; //The main operation is done in the while condition     while((*dest++ = *src++)! =' /') {NULL; }        //returns the copy string header address for easy concatenating, such as strlen (strcpy (dest, "Hello"))    returnto ;}/** Description: String copy version 2 * Parameters: dest Destination Address, SRC Source address * Return: Return copy good address, if error, undefined * exception: possible string overflow, and dest occupied space is not as large as SRC. */Char*STRCPY_V2 (Char*dest,Const Char*src) {    Char*d =dest; CharC;  while((c=*src++)! =' /')    {        * (dest++) =C; }        *dest=' /'; returnD;}/** Description: String copy version 2 (Can you find out the cause of the error) * Parameter: dest Destination address, SRC Source address * Return: Return copy good address, if error, undefined * exception: possible string overflow, and dest occupy space is not as large as SRC. */Char*strcpy_v2_error (Char*dest,Const Char*src) {    Char*d =dest; CharC;  while((c=*src++)! =' /')    {        * (d++) =C; }        *d=' /'; returnD;}/** Description: String copy version 3 * Parameters: dest Destination Address, SRC Source address * Return: Return copy good address, if error, undefined * exception: possible string overflow, and dest occupied space is not as large as SRC. */Char*strcpy_v3 (Char*dest,Const Char*src) {    Char*d =dest; CharC;  while(*src)*dest++ = *src++; *dest=' /'; returnD;}/** Description: String Copy version 4 * Parameters: dest Destination Address, SRC Source address * Return: Return copy good address, if error, undefined * exception: possible string overflow, and dest occupied space is not as large as SRC. */Char*STRCPY_V4 (Char*dest,Const Char*src) {    Char*d =dest; CharC;  while((*dest = *src)! =' /') {src++; Dest++; }            *dest=' /'; returnD;}/** Description: String copy version 5 * Parameters: dest Destination Address, SRC Source address * Return: Return copy good address, if error, undefined * exception: possible string overflow, and dest occupied space is not as large as SRC. Restrict keyword-qualified strings cannot overlap. */Char*STRCPY_V5 (Char* _restrict dest,Const Char*_restrict src) {    Char*d =dest; CharC;  while((*dest = *src)! =' /') {src++; Dest++; }            *dest=' /'; returnD;}/** Description: String Copy version 6 * Parameters: dest Destination Address, SRC Source address * Return: Return copy good address, if error, undefined * exception: possible string overflow, and dest occupied space is not as large as SRC. Restrict keyword-qualified strings cannot overlap. */Char*STRCPY_V6 (Char* _restrict dest,Const Char*_restrict src) {    Char*d =dest; CharC;  while(*dest++=*src++); returnD;}int_tmain (intARGC, _tchar*argv[]) {    Charbuf[ +]; Char*buf2 = (Char*)calloc( -,sizeof(Char)); Char*BUF3 = (Char*)malloc( -*sizeof(Char)); Char*buf5 = (Char*)malloc( -*sizeof(Char)); Char*BUF6 = (Char*)malloc( -*sizeof(Char)); printf ("using strcpy_v1,the string ' hello,world ' s length is:%d\n", strlen (STRCPY_V1 (BUF,"Hello,world"))); printf ("using strcpy_v2,the string ' this was the best age ' s length is:%d\n", strlen (Strcpy_v2 (BUF2," the best age"))); printf ("using strcpy_v2,the string ' this was the best age ' s length is:%d\n", strlen (Strcpy_v2_error (BUF2," the best age"))); printf ("using strcpy_v3,the string ' this was the best age ' s length is:%d\n", strlen (Strcpy_v3 (BUF3," the best age"))); printf ("using strcpy_v5,the string ' this was the best age ' s length is:%d\n", strlen (STRCPY_V5 (Buf5," the best age"))); printf ("using strcpy_v6,the string ' this was the best age ' s length is:%d\n", strlen (Strcpy_v6 (BUF6," the best age"))); System ("Pause"); return 0;}

Transferred from: http://www.cnblogs.com/zxher/archive/2010/07/20/1781209.html

String copy function strcpy notation _ go

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.