| 
          #include <stdio.h>#define N 300
 
 void mystrcpy(char *, char *, int);
 int mystrlen(char *);
 int main(int argc, char *argv[])
 {
 char ch1[N],ch2[N];
 char *p_ch1,*p_ch2;
 int idx,len;
 p_ch1 = ch1;
 p_ch2 = ch2;
 printf("please input source string:\n");
 gets(ch1);
 printf("please input the index:");
 scanf("%d",&idx);
 len = mystrlen(p_ch1);
 while (idx < 0 || idx > len )
 {
 printf("your input index value is error,\nthe index >= 0 and index < %d,please reinput index value:",len);
 scanf("%d",&idx);
 }
 mystrcpy(p_ch1,p_ch2,idx);
 printf("the new string is : '%s'\n",p_ch2);
 system("pause");
 return 0;
 }
 
 void mystrcpy(char *from, char *to,int idx)
 {
 while (*to++ = from[idx++]);
 }
 
 int mystrlen(char *string)
 {
 int i = 0;
 while (*string++)
 {
 i++;
 }
 return i;
 }
 
 |