1、Word;typedef struct xiangWord w;struct xiang *next;LinkWord;LinkWord *Createnote(void);void dealwith(LinkWord *L,char c);int compare(char const p,char const c); void storage(char p,char c);void display(LinkWord const *L); void clear(char p,int n);void DeletNode(LinkWord *s, LinkWord *p); int main(vo
2、id)char cMax=; int i=0,max=0; char ch=0char sourceMax= char endMax=LinkWord *L=Createnote();/头结点LinkWord *s=L,*p=NULL,*q=NULL; FILE *fp1=NULL,*fp2=NULL;printf(请输入源文件路径:); gets(source);请输入输出文件路径:gets(end); fp1=fopen(source,rif(fp1=NULL)printf(Cant open this file!nexit(0); while( (ch=fgetc(fp1)!=EOF )
3、if( (ch=65&ch=97&=122) )ci+=ch; continue;if(c0c0=122) )dealwith(L,c);/处理有效单词clear(c,Max);i=0;fclose(fp1); fp2=fopen(end,wif(fp2=NULL)printf( while(q = p = s-next)if(p = NULL)break; max = p-w.n; while(q != NULL)if(q-w.n p-w.n) p = q; q = q-next;fprintf(fp2,%s.%dn,p-w.p,p-w.n);DeletNode(s,p);/删除 s 链表中
4、的 p 指向的结点fclose(fp2); free(L);nn 操作成功,请在%s 中查看结果!nn,end);按任意键结束! getch();return 0;void DeletNode(LinkWord *s, LinkWord *p)/删除 s 链表中的 p 指向的结点LinkWord *q = s;while(q-next != p) q = q-nextq-next = p- free(p);void clear(char p,int n)/清空 c 数组int i=0;for(i = 0; i = NULL)/查找链表中是否存在这个单词p=p-if( compare(p-w.p
5、,c) )p-w.n+; return;if(p-next = NULL)/不存在就存放在最后next = Createnote();next-w.n = 1;storage(p-w.p,c);/将 c 中的单词存到结点中int compare(char const p,char const c)/判断 p 中单词与 c 中单词是否相同for( ;*p != & *c ! ; ) if( *p+ != *c+)return 0;return (*p = *c = )?1:0;LinkWord *Createnote(void)LinkWord *L = (LinkWord *)malloc(sizeof(LinkWord); L-next = NULL;L-w.n = 0;return (L);void storage(char p,char c)/将数组 c 中的单词存到数组 p 中while( *p+ = *c+ )void display(LinkWord const *L)LinkWord const *p=NULL;for( p = L;= NULL; p = p-next ) printf(%s.%dn实验结果截图:
copyright@ 2008-2023 冰点文库 网站版权所有
经营许可证编号:鄂ICP备19020893号-2