如何找到最大的内部单词

问题描述

我现在有一段英语句子,需要用C进行切割(类似于python中的split方法),得到其中的最大长度的单词(注意,简化为内部不带有标点)

src

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
int main()
{
    char A[100];
    gets(A);
    int count = 0;
    char temp1[100];
    temp1[0] = 0;
    int len = strlen(A);
    for (int i = 0; i<len; i++)
    {
        if (isspace(A[i]))
        {
            A[i] = 0;
        }
    }
    strcpy(temp1, A);
    for (int i = 0; i<len; i++)
    {
        if (A[i] == 0 && strlen(A+i+1) > strlen(temp1))
        {
            count = i;
        }
            
    }
    puts(A+count+1);

    return 0;
}
posted @ 2020-06-15 04:06  一只小小郑  阅读(84)  评论(0编辑  收藏  举报