阅读背景:

有一字符串,包含n个字符。写一函数,将此字符串中从第m个字符开始的全部字符复制成为另一个字符串

来源:互联网 
#include<stdio.h>
#include<string.h>
int main()
{
	int copy(char *p1,char *p2,int m);
	char p[20],q[20];
	int m,i;
	printf("请输入p的字符串:");
	gets(p);
	printf("请输入m的值:");
	scanf("%d",&m);
	if(strlen(p)<m)  //判断字符串p的长度是否比m的小
	{
		printf("error!");
	}
	copy(p,q,m);
	printf("%s\n",q);
	return 0;
}
int copy(char *p1,char *p2,int m)
{
	p1=p1+(m-1);//或直接将指针p1的地址指向m的位置
	while(*p1!='
#include<stdio.h>
#include<string.h>
int main()
{
	int copy(char *p1,char *p2,int m);
	char p[20],q[20];
	int m,i;
	printf("请输入p的字符串:");
	gets(p);
	printf("请输入m的值:");
	scanf("%d",&m);
	if(strlen(p)<m)  //判断字符串p的长度是否比m的小
	{
		printf("error!");
	}
	copy(p,q,m);
	printf("%s\n",q);
	return 0;
}
int copy(char *p1,char *p2,int m)
{
	p1=p1+(m-1);//或直接将指针p1的地址指向m的位置
	while(*p1!='\0')
	{
		*p2=*p1;
		p1++;
		p2++;
	}
	*p2='\0';
}


') { *p2=*p1; p1++; p2++; } *p2='
#include<stdio.h>
#include<string.h>
int main()
{
	int copy(char *p1,char *p2,int m);
	char p[20],q[20];
	int m,i;
	printf("请输入p的字符串:");
	gets(p);
	printf("请输入m的值:");
	scanf("%d",&m);
	if(strlen(p)<m)  //判断字符串p的长度是否比m的小
	{
		printf("error!");
	}
	copy(p,q,m);
	printf("%s\n",q);
	return 0;
}
int copy(char *p1,char *p2,int m)
{
	p1=p1+(m-1);//或直接将指针p1的地址指向m的位置
	while(*p1!='\0')
	{
		*p2=*p1;
		p1++;
		p2++;
	}
	*p2='\0';
}


'; }#include<stdio.h> #include<string.h> int main()



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: