标题:求教把笑面的程序改改 是他输出最短单词 新手求教啊 各位!!!!!!!!
取消只看楼主
熊猫煮粥
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2010-7-5
 问题点数:0 回复次数:0 
求教把笑面的程序改改 是他输出最短单词 新手求教啊 各位!!!!!!!!
#include<stdio.h>
#include <string.h>
void longest(char a[]);
int d,c,n;
void main()
{
    char a[1000];
    memset(a,'\0',1000);//初始化数组。
   
    printf("请用英文输入一句话\n");
    gets(a);
   
    longest(a);
   
    for(;c<d;c++)
        printf("%c",a[c]);
    printf("\n");
}


void longest(char a[])
{
    int i=0,max=0;
    while(a[i]!='\0')
    {  
        n=0;
        while(a[i]!=' ')
        {   
            if (a[i]=='\0')//当a[i]为‘\0’的时候跳出循环。
            {
                break;
            }   
            n++;
            i++;   
            
        }
        if(n>max){max=n;d=i;c=d-max;}//c为最长单词的起始字母位置,d为结束位置。
        i++;
    }
}
   
搜索更多相关主题的帖子: 单词 面的 
2010-07-07 09:17



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




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

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