字符串截取 P279_107

来源:互联网 发布:淘宝高达模型 编辑:程序博客网 时间:2024/06/10 09:46
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
using namespace std;
int main()
{
    void copyStr(char*str1,char *str2,int m);
    int m;
    charstr1[20],str2[20];
    printf("Inputstring:");
    gets(str1);
    printf("which characterthat begin to copy?");
   scanf("%d",&m);
    if(strlen(str1)
       printf("Input error!");
    else
    {
       copyStr(str1,str2,m);
       printf("result:%s\n",str2);
    }

    return 0;
}


void copyStr(char *str1,char *str2,int m)
{
    int n = 0;

    while(n
    {
       str1++;
       n++;//寻找到复制开始位置
    }
    while(*str1!='\0')
    {
       *str2 = *str1;
       str1++;
       str2++;
    }
    *str2 = '\0';
}

0 0
原创粉丝点击