首页 > 其他 > 详细

substr函数

时间:2015-10-14 01:48:00      阅读:323      评论:0      收藏:0      [点我收藏+]
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
void substr(char dst[],char src[],int start,int len)
{
	int i=0;
        for(i=start;i<start+len;i++)
	{
		strcpy(dst,src);
	    printf("%c",dst[i]);
	}	
	dst[i]=‘\0‘;
	printf("\n");
}
int main()
{
	char src[20]="hello world!";
	char dst[20];
	int i=0,len=0,start;
	int LEN=sizeof(src)/sizeof(src[0]);
	printf("请输入所需的start、len : ");
	scanf("%d%d",&start,&len);
	
	if(len>=LEN)
	{
		printf("请重新输入所需的start、len : ");
		scanf("%d%d",&start,&len);
	}
	substr(dst,src,start,len);
	system("pause");
	return 0;
}


本文出自 “花开彼岸” 博客,请务必保留此出处http://zxtong.blog.51cto.com/10697148/1702637

substr函数

原文:http://zxtong.blog.51cto.com/10697148/1702637

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!