#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';
}
从原字符串的第m个开始的全部字符复制成为另一个字符串
最新推荐文章于 2024-12-15 15:02:02 发布
该博客介绍了一个简单的C语言程序,用于从用户输入中获取字符串并根据指定字符开始复制子字符串,同时处理输入错误。

9663

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



