//#include "stdafx.h"//vc++6.0加上这一行.
#include "stdio.h"
#include "ctype.h"
#include "string.h"
struct abc{
int n;
char w[21];
};
void main(void){
struct abc wn[500],t;
int i,j,k,x;
FILE *fp;
if((fp=fopen("intxt.txt","r"))==NULL){
printf("Failed to open the input file...\n");
exit(0);
}
memset((char *)wn,'\0',sizeof(wn));
i=j=0;
while((wn[i].w[j]=getc(fp))!=EOF){
if(isalpha(wn[i].w[j])) j++;
else{
wn[i].w[j]='\0';
for(k=0;k if(!strcmp(wn[i].w,wn[k].w)){
wn[k].n++;
break;
}
if(k>=i && j) wn[i++].n++;
j=0;
}
}
fclose(fp);
for(j=0;j for(x=j,k=j+1;k if(wn[x].n>wn[k].n) x=k;
if(x!=j){
t=wn[j];
wn[j]=wn[x];
wn[x]=t;
}
}
if((fp=fopen("outtxt.txt","w"))==NULL){
printf("Failed to open the output file...\n");
exit(0);
}
for(i=0;i
printf("%s\t%d\n",wn[i].w,wn[i].n);
}
fclose(fp);
}
#include
路过!帮顶!