网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
11月17日漏签0天
c++吧 关注:642,462贴子:2,116,702
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 0回复贴,共1页
<<返回c++吧
>0< 加载中...

【提问】这个程序运行后是乱码,请大神指教(@_@;)?

  • 只看楼主
  • 收藏

  • 回复
  • 酒杯里的吉娃娃
  • ,
    1
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
设计程序,统计并输出一篇英文文章(文本文件)中的各个单词出现的次数。
#include <stdio.h>
#include <stdlib.h>
struct string
{
char data;
string *next;
};
#define str string
struct wordbook
{
str *c;
int time;
struct wordbook *next;
};
#define wb wordbook
void insert(str *a,wb *p)
{
wb *temp;
temp=(wb*)malloc(sizeof(wb));
temp->next=p->next;
p->next=temp;
temp->time=1;
temp->c=a;
}
void add(char a,str *p)
{
str *temp;
temp=(str*)malloc(sizeof(str));
temp->next=p->next;
p->next=temp;
temp->data=a;
}
str* readword(FILE *f)
{
char va;
str *p,*head;
head=(str*)malloc(sizeof(str));
head->next=NULL;
p=head;
va=fgetc(f);
if(va!=EOF)
{
while((va<65&&va>90)||(va<97&&va>122))
{
va=fgetc(f);
}
while((va>=65&&va<=90)||(va>=97&&va<=122))
{
add(va,p);
p=p->next;
va=fgetc(f);
}
p->next=NULL;
}
else
{
p->data=va;
p->next=NULL;
}
return head;
}
bool strcmp(str *a,wb *p)
{
int i,j;
for(i=0,j=0;a+i!=NULL&&(p->c)+j!=NULL;)
{
if((a+i)->data==((p->c)+j)->data)
i++,j++;
else
break;
}
if(a+i==NULL&&(p->c)+j==NULL)
return 0;
else
return 1;
}
bool search(str *a,wb *p)
{
for(;p->next!=NULL;)
{
p=p->next;
if(strcmp(a,p)==0)
return true;
}
return false;
}
void conduct(str *a,wb *p)
{
int flag;
flag=search(a,p);
if(flag==1)
p->time++;
else
insert(a,p);
}
void print (wb *p)
{
for(;p->next!=NULL;)
{
int i;
p=p->next;
for(i=0;(p->c)+i!=NULL;i++)
printf("%c ",((p->c)+i)->data);
printf("%d\n",p->time);
}
}
void main()
{
wb *head,*p;
str *a;
FILE* f = fopen("d:\\abc.txt","r");
head=(wb*)malloc(sizeof(wb));
head->next=NULL;
if(f==NULL)
printf("文本为空,无法完成统计");
else
{
for(a=readword(f);a->data!=EOF;)
{
p=head;
conduct(a,p);
a=readword(f-1);
}
print(head);
}
fclose(f);
system("pause");
}


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 0回复贴,共1页
<<返回c++吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示