string - strcat源码

来源:互联网 发布:做seo有前景吗 编辑:程序博客网 时间:2024/04/29 20:05
////  main.cpp//  AUTO_PRO////  Created by yanzhengqing on 12-12-11.//  Copyright (c) 2012年 yanzhengqing. All rights reserved.//#include using namespace std;/*** *char *strcat(dst, src) - concatenate (append) one string to another * *Purpose: *       Concatenates src onto the end of dest.  Assumes enough *       space in dest. * *Entry: *       char *dst - string to which "src" is to be appended *       const char *src - string to be appended to the end of "dst" * *Exit: *       The address of "dst" * *Exceptions: * *******************************************************************************///////////////////////////////////////////////////////////////////////////////////*说明:  1. __cdecl 是C Declaration的缩写(declaration,声明),表示C语言默认的函数调用方法:所有参数从右到左依次入栈,这些参数由调用者清除,称为手动清栈。被调用函数不会要求调用者传递多少参数,调用者传递过多或者过少的参数,甚至完全不同的参数都不会产生编译阶段的错误。  2.  在字符串dest之后连接上src  3.  按照ANSI(American National Standards Institute)标准,不能对void指针进行算法操作,即不能对void指针进行如p++的操作,所以需要转换为具体的类型指针来操作,例如char *。(引用网友的结论)*/char * __cdecl strcat (                       char * dst,                       const char * src                       ){    char * cp = dst;    while( *cp )        cp++;                   /* find end of dst */    while( *cp++ = *src++ ) ;       /* Copy src to end of dst */    return( dst );                  /* return dst */}int main(){    char brc[50] = "blog.csdn.net/";    const char src[50] = "barry_yan";    strcat(brc,src);    cout<<brc<    return 0;}
0 0
原创粉丝点击