c程序设计第四版谭浩强
有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串。
c程序设计第四版谭浩强课后答案
以下是此题的【c源代码】,需要【c++源代码】请点击进入
#include <stdio.h>
#include <string.h>
int main()
{void copystr(char *,char *,int);
int m;
char str1[20],str2[20];
printf("input string:");
gets(str1);
printf("which character that begin to copy?");
scanf("%d",&m);
if (strlen(str1)<m)
printf("input error!");
else
{copystr(str1,str2,m);
printf("result:%s\n",str2);
}
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/c/post/tanhaoqiang_8.7.html
本站文章搜索: