zoukankan
html css js c++ java
统计字符串中单词的个数
判断的依据是 空格' '字符
#include
"
stdio.h
"
#include
"
conio.h
"
#include
"
string.h
"
int
count_words(
char
str[]);
void
main()
{
int
n;
char
s[
80
];
clrscr();
printf(
"
Input a string:
"
);
gets(s);
n
=
count_words(s);
printf(
"
Word number is %d
"
,n);
}
int
count_words(
char
str[])
{
int
k,num
=
0
;
k
=
strlen(str);
do
{
k
--
;
}
while
(str[k]
==
'
'
);
str[k
+
1
]
=
'
\0
'
;
k
=
0
;
while
(str[k]
==
'
'
) k
++
;
if
(str[k]
!=
'
\0
'
) num
=
1
;
while
(str[k]
!=
'
\0
'
)
{
if
(k
>
0
&&
str[k]
==
'
'
&&
str[k
-
1
]
!=
'
'
)
num
++
;
k
++
;
}
return
num;
}
查看全文
相关阅读:
flare3d_plane
flare3d_TextureFilter
flare3d_animation
flare3d黄色星球案例再次解读整理
pureMVC(二)
flare3d_ColladaLoader
flare3d_clone
四则运算
15章
带界面的四则运算
原文地址:https://www.cnblogs.com/qixin622/p/622285.html
最新文章
福布斯评科技未来五大趋势:电脑消失融入生活时间
硅谷芯微南山中心、龙华中心同步授课
PCB电路板设计实战班
单片机高手密决,
AMD再度重申:不会做手机芯片
硅谷芯微2013年3月课程优惠信息
手机操作系统:自主力量能否崛起
有一样东西,其实比才华更难得
Android之父卸任意味着什么?
写给对MCU感兴趣的读者
热门文章
CF580D Kefa and Dishes 题解
P4036 [JSOI2008]火星人 题解
P5055 【模板】可持久化文艺平衡树 题解
UVA1402 Robotic Sort 题解
P2633 Count on a tree 题解
『学习笔记』Splay
『学习笔记』可持久化线段树(主席树)
flare3d_FLSL
flare3d_Particles粒子
pureMvc(一)
Copyright © 2011-2022 走看看