📄 我的数据结构的实验作业(一个简单的行编辑程序)_数据结构与算法_数据结构算法_c语言_c 语言之家.htm
字号:
borderColor=#e2ca9f vAlign=top width="69%">
<TABLE align=center border=0 cellPadding=0 cellSpacing=0
width="100%">
<TBODY>
<TR>
<TD height=40 width="100%"></TD></TR>
<TR>
<TD>
<FORM action=Readnews.asp?newsid=3526&id2=3526
method=post name=form1>
<CENTER><!-- <input type=submit name=aa value="点击关闭浮动图标" width=20 title="点击广告支持本站">--></CENTER></FORM></TD></TR>
<TR>
<TD align=middle bgColor=#dddddd height=20
style="FONT-SIZE: 18px" vAlign=bottom
width="85%"><STRONG><FONT color=#003399
size=4><B>我的数据结构的实验作业(一个简单的行编辑程序)
</B></FONT></STRONG></TD><BR></TR>
<TR>
<TD align=middle width="100%"><BR></TD></TR>
<TR>
<TD align=middle style="FONT-SIZE: 9pt"
width="100%">发表日期:2004年5月22日 作者:blackcat 已经有836位读者读过此文</TD></TR>
<TR>
<TD align=middle width="100%"><!--下面的这一句是设置阅读文本区的宽度-->
<TABLE align=center border=0 cellPadding=0 cellSpacing=0
style="TABLE-LAYOUT: fixed" width="90%">
<TBODY>
<TR>
<TD align=middle width="100%"></TD></TR>
<TR>
<TD style="WORD-WRAP: break-word"><FONT
class=news><BR>
<P>#include <e:\study\c\head.h><BR>#include
<stdio.h><BR>#include
<stdlib.h><BR>#include
<string.h><BR>#include
<ctype.h><BR>#include
<conio.h><BR>#define LISTSIZE 80<BR>typedef
struct text<BR>{<BR> char string[80];//
存储每一行的元素<BR> struct text *next;//
指向后一个节点的指针<BR> struct text *pre;//
指向前一个节点的指针<BR> int num;//
每一行元素的长度<BR> int flat;//
确定此行是否被删除的标志<BR>}text;<BR>FILE *fp,*out;<BR>text
*head;<BR>int n=0,sum,delnum,xiugai=0,page=0;</P>
<P>void
byebye()<BR>{<BR> puts("\t\t\t********
*
*
********");<BR> puts("\t\t\t*
* *
* *
");<BR> puts("\t\t\t*
* *
* *
");<BR> puts("\t\t\t*
* *
* *
");<BR> puts("\t\t\t********
*
********");<BR> puts("\t\t\t*
*
* *
");<BR> puts("\t\t\t*
*
* *
");<BR> puts("\t\t\t*
*
* *
");<BR> puts("\t\t\t********
*
********");</P>
<P>}</P>
<P><BR>void
HELP()<BR>{<BR> printf("\n\t**********************************************************\n");<BR> printf("\t**
打开文件: o<行号><文件名><回车>
**\n");<BR> printf("\t** 行插入格式:
i<行号><回车><文本><回车>
**\n");<BR> printf("\t** 行删除格式:
d<行号1>[<空格><行号2>]<回车>
**\n");<BR> printf("\t** 活区切换格式:
n<回车>
**\n");<BR> printf("\t** 活区显示格式:
p<回车>
**\n");<BR> printf("\t**
注意:在执行所有命令前必须先用o命令打开文件,并
**\n");<BR> printf("\t**
用p命令显示出来!!!
**\n");<BR> printf("\t**********************************************************\n");<BR> system("pause");<BR> printf("\n\n\n");<BR> <BR>}</P>
<P> </P>
<P>void
ABOUT()<BR>{<BR> printf("\n\t\t*****************************************\n");<BR> printf("\t\t**
作者:BLACKCAT
**\n");<BR> printf("\t\t**
单位:ZZU
**\n");<BR> printf("\t\t** <A
href="mailto:E-mail:blackcat242@etang.com">E-mail:blackcat242@etang.com</A>
**\n");<BR> printf("\t\t*****************************************\n");<BR> system("pause");<BR> system("cls");<BR> printf("\n\n\n");<BR>}</P>
<P>void Createlist()<BR>{<BR> text
*p1,*p2;<BR> p1=p2=(text
*)malloc(sizeof(text));<BR> head=NULL;<BR> while(n<10)<BR> {<BR>
n=n+1;<BR> if(n==1) head=p1;<BR> else
<BR> {<BR>
p2->next=p1;<BR>
p1->pre=p2;<BR>
p1->flat=0;<BR> }<BR>
p2=p1;<BR> p1=(text
*)malloc(sizeof(text));<BR> }<BR> p2->next=NULL;<BR>}</P>
<P>void freemem()<BR>{<BR> text
*p;<BR> for(p=head;head!=NULL;)<BR> {<BR>
head=p->next;<BR> free(p);<BR>
p=head;<BR> }<BR>}<BR>int
EDIT()<BR>{<BR> <BR> char
cmd;<BR> do<BR> {<BR>
cmd=getchar();<BR>
printf("\n请输入命令(按E键退出):");<BR>
cmd=getchar();<BR> switch(cmd)<BR>
{<BR> case 'e':<BR> case
'E':<BR>
if(xiugai==1)<BR>
saveall();<BR>
freemem();<BR>
system("cls");<BR> return
0;<BR> case 'o':<BR> case
'O':<BR>
Openfiles();<BR>
break;<BR> case 'p':<BR>
case 'P':<BR>
Createlist();<BR>
display();<BR>
break;<BR> case 'n':<BR>
case 'N':<BR>
saveanddisplay(10);<BR>
break;<BR> case 'd':<BR>
case 'D':<BR>
del();<BR>
break;<BR> case 'i':<BR>
case 'I':<BR>
insert();<BR>
break;<BR>
default:printf("\n\n\n!!!输入错误!!!");<BR>
}<BR> }while(cmd!='e'&&cmd!='E');<BR> return
0;<BR>}</P>
<P>int Openfiles()<BR>{<BR> char
name[30],outname[30];<BR> puts("请输入要打开的文件名:");<BR> scanf("%s",name);<BR> if((fp=fopen(name,"r+"))==NULL)<BR> {<BR>
printf("打不开原文件! \n");<BR>
exit(0);<BR> }<BR> puts("请输入要写入的文件名:");<BR> scanf("%s",outname);<BR> if((out=fopen(outname,"w+"))==NULL)<BR> {<BR>
printf("打不开目标文件!\n");<BR>
exit(0);<BR> }<BR> return 0;<BR>}</P>
<P><BR>int display()<BR>{<BR> int
i;<BR> char conti='y';<BR> text
*p;<BR> while((!feof(fp))&&(conti=='y'||conti=='Y'))<BR> {<BR>
<BR> page++;<BR>
printf("\t\t第%d页\n",page);<BR>
for(i=0,p=head,sum=0;(i<10)&&(!feof(fp));i++,p=p->next)<BR>
{ <BR>
fgets(p->string,sizeof(p->string),fp);<BR>
puts(p->string);<BR>
p->flat=1;<BR>
p->num=strlen(p->string);<BR>
sum=sum+p->num;<BR> }<BR>
puts("Continue?(Y/N):");<BR>
conti=getche();<BR> if(feof(fp))<BR>
{<BR>
puts("\n文件已经结束!");<BR> return
0;<BR> }<BR> }<BR> return
0;<BR>}<BR>int saveanddisplay(int hang)//
命令n执行的函数<BR>{<BR> int
i,endflat=0;<BR> char
conti='y';<BR> text
*p=NULL;<BR> page++;<BR> for(i=0,p=head;i<hang;i++,p=p->next)
file:// 将活区写入文件<BR>
if(p->flat==1)<BR> {<BR>
fputs(p->string,out);<BR>
p->flat=0;<BR>
}<BR> if(!feof(fp))<BR>
printf("\t\t第%d页\n",page);
<BR> for(i=0,p=head,sum=0;(i<10)&&(!feof(fp));i++,p=p->next)//
从文件读入活区<BR>
if(fgets(p->string,sizeof(p->string),fp))<BR>
{<BR> puts(p->string);
<BR> p->flat=1;<BR>
p->num=strlen(p->string);<BR>
sum=sum+p->num;<BR>
}<BR> if(feof(fp))<BR>
printf("文件已经结束!");<BR> return 0;<BR>}</P>
<P>int saveall()//
退出编辑函数后执行的函数,将所有的内容存盘<BR>{<BR> int
i,endflat=0;<BR> char
conti='y';<BR> text
*p;<BR> for(i=0,p=head;i<10;i++,p=p->next)
file:// 将活区写入文件<BR>
if(p->flat==1)<BR> {<BR>
fputs(p->string,out);<BR>
p->flat=0;<BR>
}<BR> while(!feof(fp))// 将其余的内容写入文件<BR>
fputc(fgetc(fp),out);<BR> return 0;<BR>}</P>
<P>int del()// 删除d命令对应的函数<BR>{<BR> text
*p1,*p2,*p3;<BR> int
min,max,i;<BR> xiugai=1;<BR> scanf("%d
%d",&min,&max);<BR> if(head==NULL)<BR> {<BR>
printf("\nlist null!\n");<BR> return
0;<BR> }<BR> p1=p2=head;<BR> for(i=0;i<min-1;i++)/*找到要删除的第一行*/<BR>
p1=p1->next;<BR> for(i=0;i<max;i++)/*找到要删除的最后一行*/<BR>
p2=p2->next;<BR> for(delnum=0;p1!=p2;p1=p1->next)/*删除中间的节点,将flat赋值0*/<BR> {<BR>
p1->flat=0;<BR>
delnum=delnum+p1->num;<BR> }<BR> for(i=0,p3=head;i<10;i++,p3=p3->next)//
显示删除后的结果<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -