坚持到底就是胜利

用心去做好这件事情

统计

留言簿(1)

阅读排行榜

评论排行榜

dream come true !(2)

count_word:
思想:用一个变量标志单词的开始和结束,也就是说 what i do is to judge where the word begin and where the word end
notes: maybe the interviewer didnot give enough information deliberately,they want me to check this detail,so i should communication with him to check the definition of word.

int  count_word( char   * s)
{
  
if ( null   ==  s)
     
return   0 ;
   
int  count  =   0 ;
   
int  i  =   0 ,flag  =   0 ;
   
while (s[i]  !=   ' \0 ' )
   
{
     
if (isalpha(s[i])  &&  flag  ==   0 )
     
{
        flag 
=   1  ; //  word begin
        count  ++ ;
      }

     
else   if (flag  ==   1 )
      
{
        
if ( ! isalpha(s[i])  &&  s[i]  !=   ' _ ' )
         flag 
=   0 ;
        
else   if (s[i]  ==   ' _ ' )
         
{
           
if ( ! isalpha(s[i + 1 ]))
              flag 
=   0 ;
         }
   
       }

      i
++ ;
    }

  
return  count;
}

posted on 2006-11-19 21:18 ailab 阅读(119) 评论(0)  编辑 收藏 引用


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理