#include "stdio.h"
#include "stdlib.h"
#include "string.h"
void copy(char *p1,char *p2,int m) // 如果不用声明的话函数就写在main()函数的前面
{
p2=p1+m; p1代表着str1的首地址,p1+m代表从第m+1开始复制
printf("%s",p2);
}
int main()
{
char str1[20],str2[20];
int m;
scanf("%s",str1);
printf("从第几个字符开始复制:\n");
scanf("%d",&m);
if(strlen(str1)<m)
printf("inter error");
else copy(str1,str2,m);
return 0;
}
#include "stdlib.h"
#include "string.h"
void copy(char *p1,char *p2,int m) // 如果不用声明的话函数就写在main()函数的前面
{
p2=p1+m; p1代表着str1的首地址,p1+m代表从第m+1开始复制
printf("%s",p2);
}
int main()
{
char str1[20],str2[20];
int m;
scanf("%s",str1);
printf("从第几个字符开始复制:\n");
scanf("%d",&m);
if(strlen(str1)<m)
printf("inter error");
else copy(str1,str2,m);
return 0;
}
本文提供了一个使用C语言实现的字符串复制示例程序,该程序允许用户指定从源字符串的哪个位置开始复制字符到另一个字符串。通过这个简单的示例,读者可以了解如何在C语言中操作字符串以及如何使用指针。
6650

被折叠的 条评论
为什么被折叠?



