在字符串中找出连续最长的英文字符串

1、不区分大小写
2、返回连续最长串的长度
3、拷贝给新串
例如:输入123abcdefg2141as324
返回最长字串为abcdefg
字串长度为7


#include 
#include 

int is_zimu(char ch)
{
    if (ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
        return 1;
    else
        return 0;
}

int find_string(char* inputstr, char* outputstr)
{
    char* pMove = inputstr;
    char* pOutStrHead = NULL;
    int outStrLen = 0;
    int len = 0;

    while (*pMove != '\0')
    {
        if (is_zimu(*pMove))
        {
            //统计每个英文字母字串的长度
            len = 0;
            char *pStrTemp = pMove;
            while (is_zimu(*pMove))
            {
                len++;
                pMove++;
            }
            if (len > outStrLen)
            {
                outStrLen = len;
                pOutStrHead = pStrTemp;
            }
        }
        else
        {
            pMove++;
        }
    }
    int copyLen = outStrLen;
    while (copyLen--)   //复制字符串到输出串中
    {
        *outputstr++ = *pOutStrHead++;
    }

    return outStrLen;
}


int main()
{
    char inputstr[128] = { 0 };
    char outputstr[128] = { 0 };
    scanf("%s", inputstr);

    int ret = find_string(inputstr, outputstr);

    printf("returnlen = %d\n", ret);
    printf("outputstr = %s\n", outputstr);
    system("pause");
    return 0;
}

测试结果:

zxv32vj23v32v2525cv45c3b5vhjbj3j2b5j2v51v32v52
returnlen = 5
outputstr = vhjbj
请按任意键继续. . .

你可能感兴趣的:(Data,Structures,and,Algorithms)