C++——有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串。用指针或引用方法处理。

没注释的源代码

#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
using namespace std;
void copystr(char *p1,char *p2,int m);
int main()
{
    char str1[100],str2[100];
    int m;
    cout<<"please input string:"<<endl;
    gets(str1);
    cout<<"which character that begin to copy?: ";
    cin>>m;
    if(strlen(str1)<m)
        cout<<"input error!";
    else
    {
        copystr(str1,str2,m);
        cout<<"now result:"<<str2;
    }
    return 0;
}
void copystr(char *p1,char *p2,int m)
{
    int n=0;
    while(n<m-1)
    {
        n++;
        p1++;
    }
    while(*p1!='\0')
    {
        *p2=*p1;
        p1++;
        p2++;
    }
    *p2='\0';
}