字符串strcpy

strcpy函数的表达方式:

//把一个char组成的字符串循环右移n个,如:“abcdefghi",n=2,移动后"hiabcdefgh"
#include <iostream>
#include <assert.h>
using namespace std;
#define MAX_LEN 20

void LoopMove(char *pstr,int steps)
{
    int n=strlen(pstr)-steps;
    char tmp[MAX_LEN];
    strcpy(tmp,pstr+n);
    strcpy(tmp+steps,pstr);
    *(tmp+strlen(pstr))='';
    strcpy(pstr,tmp);
}

 char* strcpy(char *strDest,const char *strSrc)
 {
     assert((strDest!=NULL)&&(strSrc!=NULL));
     char *address=strDest;
     while((*strDest++=*strSrc++)!='')
         NULL;
     return address;
 }


int _tmain(int argc, _TCHAR* argv[])
{
    char s[]="abcdefghi";
    LoopMove(s,2);
    cout<<s<<endl;
    return 0;
}

 PS:使用strcpy函数时一定要注意前面目的数组的大小必须大于后面字符串的大小,否则便是访问越界。

原文地址:https://www.cnblogs.com/Mikuroro/p/4570062.html