第二次作业

https://edu.cnblogs.com/campus/nenu/2016CS/homework/2139

#include<stdio.h> #include<string.h> #include<stdlib.h> #define N 10000 #define path "D:\wtff.txt" int main(){ FILE *fq; char s[N],word[N][50],w[N]; int i,no=0; fq=fopen(path,"r"); while (!feof(fq)) { fscanf(fq,"%c",&s[i]); i++;//字符个数 } for(int j=0;j<i;j++){ printf("%c",s[j]); if(s[j]==' '||s[j]==' ') no++; } no++;//单词个数 int c=0; //第几个单词 for(int a=0;a<i;a++)//找出空格和回车 if(s[a]==' '||s[a]==' ') { for(int b=0;b<a;b++) word[c][b]=s[b];//把单词赋给word c++; for(int d=b;d<i;d++) s[d-b]=s[d];//覆盖已经赋值给单词的字符 } for(int e=0;e<no;e++){ int h=0;//某个单词的个数 for(int f=e;f<no;f++) if(word[e]==word[f]){ h++; word[f]=word[f+1]; } printf("%c %d",word[e],h); } }

  

原文地址:https://www.cnblogs.com/huangl816/p/9729031.html