读取文件查出单词出现次数_C程序,读取文本并计算特定单词的所有出现次数...

读取文件查出单词出现次数

C program which reads a text and count all occurrences of a particular word

#include<stdio.h> #include<conio.h> #include<string.h>

#include <stdio.h> #include <conio.h> #include <string.h>

void main() { int i=0,j=0,count=0; char str1[100],str2[20],str3[20]; clrscr(); printf(“Enter the text: “); gets(str1);

void main(){int i = 0,j = 0,count = 0; 字符str1 [100],str2 [20],str3 [20]; clrscr(); printf(“输入文字:”); gets(str1);

printf(“Enter word to count: “); gets(str2);

printf(“输入要计数的单词:”); gets(str2);

while(str1[i]!=”) { while(str1[i]!=’ ‘&&str1[i]!=”) //copying the word from the text to a new string str3[j++]=str1[i++];

while(str1 [i]!=”){while(str1 [i]!=''&& str1 [i]!=”)//将单词从文本复制到新字符串str3 [j ++] = str1 [i ++] ;

str3[j]=”; //assigning null character at the end of string j=0;

str3 [j] =”; //在字符串j = 0的末尾分配空字符

if((strcmpi(str2,str3))==0) //comparing the given word with the copied word count++;

if((strcmpi(str2,str3))== 0)//比较给定的单词和复制的单词count ++;

if(str1[i]==”) break; else i++; }

if(str1 [i] ==”)中断; 否则我++; }

printf(“No. of words are %d”,count); getch(); }

printf(“字数为%d”,计数); getch(); }

翻译自: https://www.thecrazyprogrammer.com/2013/07/c-program-which-reads-text-and-count.html

读取文件查出单词出现次数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值