读取文件查出单词出现次数
#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
读取文件查出单词出现次数