当前位置:网站首页>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);
}
边栏推荐
- 为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
- Other 7 features of TCP [sliding window mechanism ▲]
- Isomorphic C language
- Count sort (diagram)
- oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
- Mock. JS usage details
- Greenplum 6.x build_ Environment configuration
- Gson转换实体类为json时报declares multiple JSON fields named
- Data analysis methodology and previous experience summary 2 [notes dry goods]
- leetcode134. gas station
猜你喜欢
Three series of BOM elements
2022-07-06 Unity核心9——3D动画
LED模拟与数字调光
LeetCode 736. Lisp 语法解析
【MySQL】数据库进阶之触发器内容详解
[Yugong series] February 2022 U3D full stack class 005 unity engine view
Markdown编辑器Editor.md插件的使用
【踩坑】nacos注册一直连接localhost:8848,no available server
【Istio Network CRD VirtualService、Envoyfilter】
xray的简单使用
随机推荐
Three series of BOM elements
串口实验——简单数据收发
[MySQL] detailed explanation of trigger content of database advanced
Panel display technology: LCD and OLED
ncs成都新电面试经验
Required String parameter ‘XXX‘ is not present
JS operation
MySQL partition explanation and operation statement
Gson converts the entity class to JSON times declare multiple JSON fields named
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
Markdown编辑器Editor.md插件的使用
外部中断实现按键实验
Goldbach conjecture C language
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
指针进阶,字符串函数
测试人一定要会的技能:selenium的三种等待方式解读,清晰明了
Interpolation lookup (two methods)
求有符号数的原码、反码和补码【C语言】
Personal deduction topic classification record
[Yugong series] February 2022 U3D full stack class 007 - production and setting skybox resources