当前位置:网站首页>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);
}
边栏推荐
- Quick sorting (detailed illustration of single way, double way, three way)
- 实现自定义内存分配器
- Other 7 features of TCP [sliding window mechanism ▲]
- Calf problem
- 【ChaosBlade:节点磁盘填充、杀节点上指定进程、挂起节点上指定进程】
- Enterprise manager cannot connect to the database instance
- [MySQL] detailed explanation of trigger content of database advanced
- Panel display technology: LCD and OLED
- Newly found yii2 excel processing plug-in
- Golang etcdv3 reports an error. The attribute in grpc does not exist
猜你喜欢
xray的简单使用
面试题:高速PCB一般布局、布线原则
Simple use of Xray
Goldbach conjecture C language
Platformization, a fulcrum of strong chain complementing chain
Greenplum6.x重新初始化
Introduction to data fragmentation
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
Quick sorting (detailed illustration of single way, double way, three way)
阿里p8推荐,测试覆盖率工具—Jacoco,实用性极佳
随机推荐
阿里p8手把手教你,自动化测试应该如何实现多线程?赶紧码住
Uniapp wechat applet monitoring network
[Yugong series] February 2022 U3D full stack class 005 unity engine view
Tronapi wave field interface - source code without encryption - can be opened twice - interface document attached - package based on thinkphp5 - detailed guidance of the author - July 6, 2022 - Novice
Three series of BOM elements
Quick sorting (detailed illustration of single way, double way, three way)
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
[Yugong series] February 2022 U3D full stack class 008 - build a galaxy scene
实现自定义内存分配器
selenium自动化集成,八年测试经验软测工程师,一篇文章带你学懂
Golang etcdv3 reports an error. The attribute in grpc does not exist
Greenplum6.x重新初始化
Three usage scenarios of annotation @configurationproperties
About using CDN based on Kangle and EP panel
Original collection of hardware bear (updated on June 2022)
模拟卷Leetcode【普通】1567. 乘积为正数的最长子数组长度
C language for calculating the product of two matrices
Problems encountered in the use of go micro