当前位置:网站首页>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);
}
边栏推荐
- oracle一次性说清楚,多种分隔符的一个字段拆分多行,再多行多列多种分隔符拆多行,最终处理超亿亿。。亿级别数据量
- Analysis of using jsonp cross domain vulnerability and XSS vulnerability in honeypot
- Personal deduction topic classification record
- ChaosBlade:混沌工程简介(一)
- 【ChaosBlade:节点 CPU 负载、节点网络延迟、节点网络丢包、节点域名访问异常】
- [南京大学]-[软件分析]课程学习笔记(一)-introduction
- Frequently Asked Coding Problems
- Unity Shader入门精要初级篇(一)-- 基础光照笔记
- [Yugong series] February 2022 U3D full stack class 005 unity engine view
- Goldbach conjecture C language
猜你喜欢
【Istio Network CRD VirtualService、Envoyfilter】
JS operation
Output all composite numbers between 6 and 1000
Category of IP address
为不同类型设备构建应用的三大更新 | 2022 I/O 重点回顾
硬核分享:硬件工程师常用工具包
Routing information protocol rip
Calf problem
Recommended by Alibaba P8, the test coverage tool - Jacobo is very practical
STM32串口寄存器库函数配置方法
随机推荐
Common operating commands of Linux
RuntimeError: Calculated padded input size per channel: (1 x 1). Kernel size: (5 x 5). Kernel size c
ESP32-ULP协处理器低功耗模式RTC GPIO中断唤醒
如何统计项目代码行数
最长上升子序列模型 AcWing 1017. 怪盗基德的滑翔翼
硬件大熊原创合集(2022/05更新)
使用Typora编辑markdown上传CSDN时图片大小调整麻烦问题
What are the advantages of commas in conditional statements- What is the advantage of commas in a conditional statement?
Upload an e-office V9 arbitrary file [vulnerability recurrence practice]
Output a spiral matrix C language
leetcode135. Distribute candy
Simulation volume leetcode [general] 1567 Length of the longest subarray whose product is a positive number
About using CDN based on Kangle and EP panel
Introduction to data fragmentation
MAC OSX php dyld: Library not loaded: /usr/local/xxxx. dylib
2022-06-30 unity core 8 - model import
Simulation volume leetcode [general] 1557 The minimum number of points that can reach all points
OpenGL帧缓冲
channel. Detailed explanation of queuedeclare parameters
Interpolation lookup (two methods)