C语言实例1—统计单词个数

我使用的DEVC++编译器,新建get_words_num.c文件

c 复制代码
#include<stdio.h>

int main()
{
	char cString[100];
	
	int iIndex,iWord=1;
	char cBlank;
	gets(cString);
	
	if(cString[0]=='\0')
	{
		printf("There is no words!\n");
	}
	else if(cString[0]==' ')
	{
		printf("first words is a blank char!\n");
	}
	else
	{
		for (iIndex=0;cString[iIndex]!='\0';iIndex++)
		{
			cBlank=cString[iIndex];
			if(cBlank==' '){
				iWord++;
			}
			
		}
		printf("%d\n",iWord);
	}
	return 0 ;
}

运行

c 复制代码
I love cats and dags
5
c 复制代码
 I love cats and dags
 first words is a blank char!

直接回车

c 复制代码
There is no words!
相关推荐
Cuit小唐几秒前
Qt炫酷仪表盘
开发语言·qt
Code额11 分钟前
ECMAScript 11 新特性
开发语言·javascript·ecmascript
Superxpang16 分钟前
JavaScript `new Date()` 方法移动端 `兼容 ios`,ios环境new Date()返回NaN
开发语言·前端·javascript·ios·typescript·安卓
大模型铲屎官1 小时前
# Unity动画控制核心:Animator状态机与C#脚本实战指南 (Day 29)
c语言·unity·c#·游戏引擎·游戏开发·动画控制·animator状态机
水w1 小时前
【Python爬虫】简单介绍2
开发语言·爬虫·python·beautifulsoup
安全菜鸟1 小时前
DeepSeek 接入 Word 完整教程
开发语言·c#·word
小白学大数据1 小时前
Scrapy结合Selenium实现搜索点击爬虫的最佳实践
开发语言·chrome·爬虫·selenium·scrapy
why1511 小时前
腾讯云golang一面
开发语言·后端·golang
vil du1 小时前
c# AI编程助手 — Fitten Code
开发语言·c#·ai编程
XW-ABAP2 小时前
c语言练习4
java·c语言·前端