标题:一组字符串,求最长字符
取消只看楼主
午夜小学徒
Rank: 2
等 级:论坛游民
威 望:3
帖 子:52
专家分:40
注 册:2014-7-17
结帖率:71.43%
已结贴  问题点数:20 回复次数:0 
一组字符串,求最长字符
/*const char sentence[] = "our Tomorrow will be better";
    printf("%s\n",sentence);
    int maxWordLength = 0,currentWordLength = 0,maxWordStartIndex = 0;
    unsigned long str_len = strlen(sentence);
    for (int i = 0; i < str_len + 1; i++) {
        char character = sentence[i];
        if (character != ' ' && character != '\0') {
            currentWordLength ++ ;
        }else{
            if(maxWordLength < currentWordLength){
                maxWordLength = currentWordLength;
                maxWordStartIndex = i - currentWordLength;
            }
            currentWordLength = 0;
        }
    }
    printf("startIndex = %d; maxLength = %d ",maxWordStartIndex,maxWordLength);
    for (int i = maxWordStartIndex; i < maxWordLength + maxWordStartIndex; i++) {
        printf("%c",sentence[i]);
    }*/
不明白“int maxWordLength = 0,currentWordLength = 0,maxWordStartIndex = 0;”的意义,请大神能讲解一下
搜索更多相关主题的帖子: character better 字符串 
2014-09-05 16:51



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-435732-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.298041 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved