C语言之计算字符串最后一个单词的长度,单词以空格隔开

//计算字符串最后一个单词的长度,单词以空格隔开。
#include<stdio.h>
#include<string.h>
#include<windows.h>
int main()
{
    char str[128];
    gets(str);
    int count=0;
    int len=strlen(str);
    for(int i=(len-1);i>=0;i--)
    {
        if(str[i]!=' ')
        {
            count++;
        }
        else
        {
            break;
        }    
    }
    printf("%d\n",count);
    system("pause");
    return 0;
}

posted @ 2016-07-05 14:49  QualityAssurance21  阅读(9881)  评论(0编辑  收藏  举报