您的位置:首页 > 编程语言

请求高人帮我看下代码,编译没有错,运行出问题 关于简单文本编辑器的

2011-06-08 18:33 756 查看
#include<stdio.h>
#include<string.h>
#include<iostream.h>
#include<stdlib.h>
#include<conio.h>
#define Link_Size 100
struct list
{
char data[80];
int length;
list *next;
list *pre;
int row;
};
class link
{
private:
list *head;
int NUM; //总行数
int C;
int N;
public:
list *CreatWord();
void PrintWord(list *head);
void CountWord(list *head);
void SearchWord(char str1[],list *head);
void DeleteWord(char str2[]);
void HeadWord();

};
void link::HeadWord()
{
printf("/t/t****************************************************/n");
printf("/t/t**** 欢迎使用简单的文本编辑器 ****/n");
printf("/t/t****************************************************/n");
}

list *link::CreatWord()
{
list *temp,*q;
char ch;
int i,j;
// head=new list;

cout<<"开始创建文本,请输入文章(输入#号结束):"<<endl;
for(j=0;j<Link_Size;j++)
{
for(i=0;i<80;i++)
{
temp=new list;
temp->length=0;
ch=getchar();
temp->data[i]=ch;
temp->length++;
if(ch=='#')
{NUM=j;
break;}
}
if(ch=='#')
{
temp->length=i;
temp->next=NULL;
break;
}
if(j==0)
{ head->next=temp;
q=temp;
}
else
{
q->next=temp;
q=temp;
}
}
q->next=head;
return head;
}
void link::PrintWord(list *head)
{
int i,j;
list *p;
p=head->next;
system("cls");
HeadWord();
printf("/n当前文章的内容是:");
for(j=0;j<=NUM&&p!=NULL;j++)
{
for(i=0;(i<80)&&(p->data[i])!='#';i++)
{
printf("%c",p->data[i]);
}
p=p->next;
}
}
void link::CountWord(list *head)
{
list *temp;

char ch;
int i,j;
int WORD=0,word=0,space=0,num=0,punct=0,sum=0;
temp=head->next;
for(j=0;j<=NUM;j++)
{
for(i=0;(i<80)&&(temp->data[i])!='#';i++)
{
ch=temp->data[i];
if((ch>='A')&&(ch<='Z'))
WORD++;
else if((ch>='a')&&(ch<='z'))
word++;
else if((ch>='0')&&(ch<='9'))
num++;
else if(ch==' ')
space++;
else if(ch==33||ch==34||ch==39||ch==44||ch==46||ch==58||ch==59||ch==63)
{punct++;}
}
sum=WORD+word+num;
}
cout<<"1、文章中大写字母的个数:"<<WORD<<endl;
cout<<"2、文章中小写字母的个数:"<<word<<endl;
cout<<"3、文章中数字的个数:"<<num<<endl;
cout<<"4、文章中标点符号的个数:"<<punct<<endl;
cout<<"5、文章中空格的个数:"<<space<<endl;
cout<<"6、文章中所有字数:"<<sum<<endl;
}
void link::SearchWord(char *str1,list *head)
{
char Data[20] ;
int i,j,k=0,sum=0;
int l=1;
list *temp;
temp=head->next;
strcpy(Data,str1);

for(i=0;i<=NUM;i++)
{
for(j=0;j<80;j++)
{
if((temp->data[j])==Data[k]) k++;
else if(Data[k]!='/0')
{
j=j-k;
k=0;
}
if(Data[k]=='/0')
{
sum++;
j=j-k+1;
printf("/t/t第%d次出现在第%d行第%d列/n",l,i+1,j+1);
l++;

k=0;
continue;}
}
temp=temp->next;
}
printf("/t/t/t字符串总共出现次数为:%d/n/n",sum);
C=sum;
N=i*80+j;
}
void link::DeleteWord(char *str2)
{ char Data[20];
list *temp,*term;
int i,j,k,m,y,num;
strcpy(Data,str2);
for(y=0;y<C;y++)
{
num=80;
k=0,m=0;
temp=head;
for(i=0;i<=NUM;i++)
{
term=temp;
temp=temp->next;
for(j=0;j<80;j++)
{
if((temp->data[j])==Data[k]) k++;
else if(Data[k]!='/0') {j=j-k;k=0;}
if(Data[k]=='/0')
{
num=j;
break;
}
}
if(num<80) break;
}
for(;i<=NUM;i++)
{
for(;j<80;j++)
{
if(j+1<k)
{
term->data[80-k+num]=temp->data[j+1];
}
else
temp->data[j-k+1]=temp->data[j+1];
}
term=temp;
temp=temp->next;
j=0;
}
}

}
void main()
{
link text;
list *head;
head=text.CreatWord();
char str1[20];
char str2[20];
int a;
do
{
text.HeadWord();
cout<<"****************************************************"<<endl;
cout<<"**** 文章内容处理菜单 ****"<<endl;
cout<<"****************************************************"<<endl;
cout<<"**** 1、查找文章中的字符或者字符串 ****"<<endl;
cout<<"**** 2、删除文章中的字符或者字符串 ****"<<endl;
cout<<"**** 3、显示当前文章内容 ****"<<endl;
cout<<"**** 4、计算文本 ****"<<endl;
cout<<"***********************************************"<<endl;
cout<<"请选择(-1退出):";
cin>>a;
if(a==-1) return ;
switch(a)
{
case 1:
cout<<"请输入您需要查找的字符或字符串:";
getchar();
gets(str1);
text.SearchWord(str1,head);
//system("cls");
break;
case 2:
cout<<"请输入您需要删除的字符或字符串:";
getchar();
gets(str2);
text.SearchWord(str2,head);
text.DeleteWord(str2);
cout<<"删除"<<str2<<"后的文章为:";
text.PrintWord(head);
//system("cls");
break;
case 3:
text.PrintWord(head);
break;
case 4:
text.CountWord(head);
break;
default:
cout<<"输入出错,请重新输入!"<<endl;
}
cout<<endl;
}while(true);
return ;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐