dream come true !(2)

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;
}

你可能感兴趣的:(dream come true !(2))