2023年简单行编辑程序实验报告.docx
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《2023年简单行编辑程序实验报告.docx》由会员分享,可在线阅读,更多相关《2023年简单行编辑程序实验报告.docx(25页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、简朴行编辑程序课程设计一.设计规定.问题描述文本编辑程序是运用计算机进行文字加工的基本软件工具,实现对文本文献 的插入、删除等修改操作。限制这些操作以行为单位进行的编辑程序称为行编辑 程序。被编辑的文本文献也许很大,所有读入编辑程序的数据空间(内存)的做法即 不经济,又不总能实现。一种解决方法是逐段的编辑。任何时刻只把待编辑文献 的一段放在内存,称为活区。试按这种方法实现一个简朴的行编辑程序,设文献 每行不超过320个字符,很少超过8 0个字符。1 .需求分析该程序要实现以下4条基本的编辑命令:(1)行插入。格式:i行号X回车X文本).V回车)将文本插入活区中第行号 行之后。(2)行删除。格式
2、:d行号1 空格行号2.回车例如删除活区中第行号1 行(到第行号2行)。(3)活区切换。格式:n回车)将活区写入输出文献,并从输入文献中读入下一段,作为新的活区。(4)活区显示。格式:P回车;逐页地(每页20行)显示活区内容,在每显示的 一页之后请用户决定是否继续显示以后各页(假如存在)。印出的每一行要前置行 号和一个空格符,行号固定占4位,增量为1。各条命令中的行号均须在活区中各行号范围之内,只有插入命令的行号可以 等于活区第一行行号减一,表达插入当前的屏幕中第一行之前,否则命令参数非 法。fr e e( i nfo);pa t c h u p(l i n enum+1,-1);)/*查找一
3、行文本*/s truct line *f i nd( i n t linenum)(stru c t 1 ine *i n fo;info=start;wh i le(inf o )(i f (linenum=in f o-n u m) retur n (inf o ); in f o =info-next;)r e turn(NULL);)/*显示文本*/vo i d list ()(stru c t li n e * i n f o;info= s ta r t;while(i n fo)p r i n tf( %d: %s n M,info-num,info- t ext); info=
4、i n fo-next;)p r i nt f ( nn );/ *存文献*/void save(c har *f n am e )stru c t1 in e *inf o ;charF I LEF I LE*fp;i f( f p= f open(fname,uwu) )=NULL)p r intf( t Can t o pen the file ! n );e x it( 0 );)pr i n t f(M t S a ved : n H);in f o=sta r t;while (i n f o )p =i n fo-lext;while (*p)putc(*p+, f p);put
5、c(rn, f p);i n f o=i n f o-next;f close(fp);/*读取文献*/void load (char *f n a m e )(struc t li n e * i n fo,*temp;char*p;FILE * fp;i ntsize, i n c t ;if(fp=fope n (f n ame, r+n) )=NULL)(p r in t f (H t Cant op e n t h e f i le !n );e xit (0);1whilc(s t art)(temp=st a rt;s t art=s t ar t -n ext;fre e (
6、t e mp);)print f (Mn t Re a d i n g. . n H );size=size o f(s t ruct line);slart=(struct 1 i ne*) mal 1 o c(s i z e);i f (! s tart)pr i ntf(nnt内存己经用完!);return;)info=s t art;p=info- t e xt;i n c 1=1;wh i le(*p= g e t c (fp) )! =EOF)(p+;w h ile ( *p=getc( f p )!-n) P+;*p=,0,;in f o -num= i net +;i n f
7、o-n e xt= (st r uc t 1 i ne*)mal 1 o c (size); if ( ! i n f onext)(p r i n t f (”nt内存已经用完!);ret u r n;)info- p ri o r =tem p ;temp二info;i n f o= i nfo- n ext;p= i n fo-text;Itemp- n ex t =NU L L ;la s t=temp;f ree(in f o);start p r ior=NUL L;i close( fp);五.测试分析1.主菜单序程辑编行 不方 单入除显文文存 用L1I仃 12 3 4 5 6迎
8、欢串 U 选 请2.行插入行 示加 单人除显文文存事 使 1 2 3 4 5 6 迎欧请选择:i 行号角1:hello2:world3:hello world3.行删除及文本显示序 程 辑 编行 不& 单人除显文文存事 用Lff仃文使1 .2.3.4.5.6.迎请选择:2请选择:31:hello2:hello uorld.保存及读取文献请选择:4 文件:占Jtello .txt Saved.欢迎使用1234单行编辑程序A请选择:5 文件名:D:hello.txtReading.4 .退出主菜单下输入5并回车即退出“简朴行编辑程序”。六.源程序清单# i nclude #include # in
9、cl u d e st r u c t 1 i n e cha r text8 1 1;int num;/*行号* /struct li n e * next;/*指向下一个输入项目的指针*/struct line *prior; /*指向前一个项目的指针 */;s truct li n e * s tart;/*指向表中第一个项目的指针*/str u ct 1 i ne last;/*指向表中最后一个项目的指针*/st r uct 1 ine * f ind(in t ) ,*dls_stor e ( s tru c t line *);v oid patchu p ( i nt,int),
10、 d elete_ t ext(), 1 i s t (),sa v e(ch a r*), load(char *);me n u_s elec t();en t e r ( i nt li n en u m);v o id main (int arg c ,ch a r *argv)(char s80, c ho i ce, f n a me 80;int li n enum=1;s tart = NULL;last=NULL;if( a r gc=2)1 o ad ( a rg v 1) ;/*读取命令行上的文献* /do (choic e =men u _sel e ct();s w
11、i tc h ( c h oice)casecase1: p rintf(行号:”);gets (s);linenum =atoi(s);e n t e r( 1 in e n u m);bre a k;case 2 : de 1 e t e _ text break;c a se 3 :list();break;case 4 :prin t f (”t 文献名gets( f name);save (fnam e );break;case 5:printf (”t 文献名:);ge t s(fname);load( f name);bre a k;case 6 : e x i t(0);)w
12、h i 1 e(l);/* 显示菜单,供用户选择*/menu_ s e lect()c har s80;in t c ;p rint f ( *欢迎使用简朴行编辑程序* * * * * * *nu);prin t f(ttttl.行插入 n);printf(”tttt2.行删除n,1);p r intf (nt t tt3.文本显示n);printf( n t lZ4.保存文献n”);prin tf(ntt t t 5 .读取文献 n );printf(tt tt6.退出 n”);p rintf(,t* * * * * * * * * * * * * * * * * * *n );doprin
13、tf( n n t t 请选择 gets(s);c =a t oi(s);while( c 6);rcturn(c);)/*将文本插在指定行端部*/ent e r( i n t 1 in e num) (line *inf o ;line *inf o ;struc tinf o =(st r u c t 1 ine *)mall o c ( s i ze o f(struct tin e );i f(! info)(printf ( l!内存不够! nu);return (NULL);)p r intf(% d :n linen u m);g ets(i n f o - text);i nf
14、o n um= 1 incnum;if (*in f o-text)(if ( f in d (lin e num) ) p a tchup (1 i n e n u m,l);if(* in f otext)s t art = dis_store (inf o );1else b re a k;linen u m+ + ;)return (linenum);)/*当文本内容插在文献中间时其下面的内容的行号必须增长1 ,而删除时,被删除的文本后面的行号必须减1*/v oid patchup(int n,i n t incr)(struct 1 in e *i;i= f i nd (n);二.概
15、要设计1 .主界面设计为了实现简朴行编辑程序,设计一个具有多个菜单项的主控菜单子程序以链接系统的各项子功能。主控菜单运营如下:串 U 选 请使 12 3 4 5 6迎行单入除显文文2 .存储结构设计该系统采用串的顺序存储结构。3 .系统功能设计(1)行插入(2)行删除(3)文本显示(4)保存文献(5)读取文献(6)退出系统三.模块设计1.模块设计木程序包含主程序模块、菜单选择模块和串操作模块。调用关系如下主程序模块菜单选择模块串操作模块whi 1 e (i)i-n u m = i-n u m+i n c r;i=i-next;I/*按行号排序后插入*/s t r u c t 1 i ne *d
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2023 简单 编辑 程序 实验 报告
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内