当前位置:网站首页>C language: count the number of words in a paragraph
C language: count the number of words in a paragraph
2022-06-25 08:45:00 【zbossz】
The big premise : Words are separated by spaces
Little premise : What I write is all lowercase .
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include<string.h>
#define size 50
int fun(char s[])
{
int i = 0, num = 0;
while (i < size)
{
if (s[i] != '\0')
{
if ((65 <= s[i] && s[i] <= 90) || (97 <= s[i] && s[i] <= 122))
{
while ((65 <= s[i] && s[i] <= 90) || (97 <= s[i] && s[i] <= 122))
i++;
num += 1;
while (s[i] == ' ')
i++;
}
}
if (s[i] == '\0')
break;
i++;
}
return num;
}
int main()
{
char s1[size];
gets(s1);
printf(" Altogether %d Word ", fun(s1));
return 0;
}

**if (s[i] != ‘\0’)** To prevent an array from being accessed beyond its bounds .
**if ((65 <= s[i] && s[i] <= 90) || (97 <= s[i] && s[i] <= 122))** To skip other types of character interference , Let the traversal of other characters pass
there i To skip .

This is to traverse the letters .

This is to traverse spaces .
边栏推荐
猜你喜欢

【515. 在每个树行中找最大值】

某次比赛wp

UEFI: repair efi/gpt bootloader

Easyplayer streaming media player plays HLS video. Technical optimization of slow starting speed

Internet of things (intelligent irrigation system - Android end)

Day 5 script and UI System

声纹技术(六):声纹技术的其他应用

Exchange: manage calendar permissions

atguigu----17-生命周期

What are the indicators of entropy weight TOPSIS method?
随机推荐
[summary] 1361- package JSON and package lock JSON relationship
wav文件(波形文件)格式分析与详解
Exchange: manage calendar permissions
How to increase the monthly salary of software testing from 10K to 30K? Only automated testing can do it
浏览器查看当前页面所有的监听事件
声纹技术(五):声纹分割聚类技术
What is the role of software validation testing? What is the price of the confirmation test report?
华泰证券在上面开股票账户安全吗?
How to analyze the grey prediction model?
进击的技术er,遇见实习岗位信息
¥3000 | 录「TBtools」视频,交个朋友&拿现金奖!
leetcode. 13 --- Roman numeral to integer
atguigu----18-组件
LVS-DR模式单网段案例
初识生成对抗网络(11)——利用Pytorch搭建WGAN生成手写数字
打新债安全性有多高啊
C language: bubble sort
【强化学习笔记】强化学习中的常见符号
Unity Addressable批量管理
Hyper-v:Hyper-v 第 1 代或第 2 代虚拟机