c++程序设计第3版谭浩强课后答案
C++编程,要求用指针或引用方法处理:
有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串。
以下是此题的【c++源代码】,需要【c源代码】请点击进入
#include <iostream>
using namespace std;
int main()
{void copystr(char *,char *,int);
int m;
char str1[20],str2[20];
cout<<"input string:";
gets(str1);
cout<<"which character do you want begin to copy?";
cin>>m;
if (strlen(str1)<m)
cout<<"input error!"<<endl;
else
{copystr(str1,str2,m);
cout<<"result:"<<str2<<endl;
}
return 0;
}
void copystr(char *p1,char *p2,int m) //字符串部分复制函数*/
{int n;
n=0;
while (n<m-1)
{n++;
p1++;
}
while (*p1!='\0')
{*p2=*p1;
p1++;
p2++;
}
*p2='\0';
}
本文链接:http://www.wb98.com/cjia/post/cjia_6.7.html
本站文章搜索: