#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
原文:http://zxtong.blog.51cto.com/10697148/1702637