📄 wordcmp.c
字号:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define fn"13-4-1.txt"
typedef struct word
{
char str[20];
int num;
struct word *nxt;
}WORD;
int main(void)
{
char s[20];
FILE *fp;
WORD *head,*p;
fp=fopen(fn,"r");
p=(WORD*)malloc(sizeof(WORD));
head=p;
head->num=1;
head->nxt=NULL;
while(fscanf(fp,"%s",s)!=EOF)
{
WORD *cmp=head;
char flag=0;
while(cmp!=NULL)
{
if(!strcmp(cmp->str,s))
{
cmp->num++;
flag=1;
break;
}
else
cmp=cmp->nxt;
}
if(!flag)
{
p->nxt=(WORD*)malloc(sizeof(WORD));
p->nxt->num=1;
p->nxt->nxt=NULL;
strcpy(p->nxt->str,s);
p=p->nxt;
}
}
p=head;
while(p!=NULL)
{
printf("%10s:%d times\n",p->str,p->num);
p=p->nxt;
}
while(head!=NULL)
{
WORD *tmp;
tmp=head;
head=head->nxt;
free(tmp);
}
fclose(fp);
system("pause");
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -