来C语言大神帮忙 大神去哪了....
答案:1 悬赏:60
解决时间 2021-01-07 04:46
- 提问者网友:世勋超人
- 2021-01-06 06:58
来C语言大神帮忙 大神去哪了....
最佳答案
- 二级知识专家网友:玩世
- 2021-01-06 08:28
#include
#include
#include
typedef struct t{char word[100];unsigned int cnt;struct t *next;}st;
st* creat(char *w)
{
st* p=(st *)malloc(sizeof(st));
strcpy(p->word,w);
p->cnt=1;
p->next=NULL;
return p;
}
st* find(st* head,char *w)
{
st* p;
for(p=head->next;p&&strcmp(p->word,w);p=p->next);
return p;
}
int main()
{
FILE *fp;
char w[100];
st *head=creat(""),*p;
if((fp=fopen("test.txt","r"))!=NULL)
{
while(!feof(fp))
{
fscanf(fp,"%*[^a-zA-Z]%[a-zA-Z]",w);
if(p=find(head,w))
{
(p->cnt)++;
}
else
{
for(p=head;p->next;p=p->next);
p->next=creat(w);
}
}
for(p=head->next;p;p=p->next)
{
printf("%s %d
",p->word,p->cnt);
}
}
return 0;
}
#include
#include
typedef struct t{char word[100];unsigned int cnt;struct t *next;}st;
st* creat(char *w)
{
st* p=(st *)malloc(sizeof(st));
strcpy(p->word,w);
p->cnt=1;
p->next=NULL;
return p;
}
st* find(st* head,char *w)
{
st* p;
for(p=head->next;p&&strcmp(p->word,w);p=p->next);
return p;
}
int main()
{
FILE *fp;
char w[100];
st *head=creat(""),*p;
if((fp=fopen("test.txt","r"))!=NULL)
{
while(!feof(fp))
{
fscanf(fp,"%*[^a-zA-Z]%[a-zA-Z]",w);
if(p=find(head,w))
{
(p->cnt)++;
}
else
{
for(p=head;p->next;p=p->next);
p->next=creat(w);
}
}
for(p=head->next;p;p=p->next)
{
printf("%s %d
",p->word,p->cnt);
}
}
return 0;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯