当前位置:网站首页>Count the number of words in the string c language
Count the number of words in the string c language
2022-07-07 08:57:00 【Please Sit Down】
Calculate formal parameters s The number of words contained in the indicated word string , Return... As a function value .
For the convenience of Statistics , Stipulate that each word is separated by a space .
Columns such as : Shape parameter s The string referred to is :This is a c language program., The return value of the function is 6.
#include <stdio.h>
int fun(char *s){
int n = 0, flag = 0;
while (*s != '\0'){
if (*s != ' ' && flag == 0){
n++;
flag = 1;
}
if (*s == ' ')
flag = 0;
s++;
}
return n;
}
int main(){
char str[81];
int n;
printf("Enter a line text:");
gets(str);
n = fun(str);
printf("There are %d words in this text.", n);
}边栏推荐
- QT charts use (rewrite qchartview to realize some custom functions)
- What are the advantages of commas in conditional statements- What is the advantage of commas in a conditional statement?
- Platformization, a fulcrum of strong chain complementing chain
- 外部中断实现按键实验
- Routing information protocol rip
- Panel display technology: LCD and OLED
- [wechat applet: cache operation]
- Problems encountered in the use of go micro
- LeetCode 736. Lisp 语法解析
- How to realize sliding operation component in fast application
猜你喜欢
随机推荐
OpenGL frame buffer
Unityshader introduction essentials personal summary -- Basic chapter (I)
Troublesome problem of image resizing when using typora to edit markdown to upload CSDN
Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical
PPT模板、素材下载网站(纯干货,建议收藏)
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
Un salaire annuel de 50 W Ali P8 vous montrera comment passer du test
Common operating commands of Linux
【istio简介、架构、组件】
【MySQL】数据库进阶之触发器内容详解
Several common database connection methods
LeetCode 736. LISP syntax parsing
求有符号数的原码、反码和补码【C语言】
[南京大学]-[软件分析]课程学习笔记(一)-introduction
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
OpenGL三维图形绘制
年薪50w阿裏P8親自下場,教你如何從測試進階
Output a spiral matrix C language
STM32串口寄存器库函数配置方法
Greenplum6.x常用语句








