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