1、数据结构源码-串操作应用举例 简单行编辑程序例 #include #include #include “keyscode.h“#include “menu.h“struct lineint charnum;char *base;typedef struct line SequListElemType;#include “sequlist.h“#define MAXLINES 1000int key;int cureditline=0;int curscrtopline=0;int cureditcol=0;int funckey;int editwinx=2;int editwiny=3;in
2、t editwinlines=20;int mainover=0;FILE *curfile;char filename255=“test.txt“;SequList *Document;char ascii(int k);printdoc(int startfileline,int startscrline);readdoc(FILE *fp);editline(int curline,int maxcolnum)char s2000;setscrcolor(BLUE,YELLOW);strcpy(s,Document-elemcurline.base);getstring(editwinx
3、,editwiny+curline-curscrtopline,s,maxcolnum);free(Document-elemcurline.base);Document-elemcurline.base=(char *)malloc(strlen(s)+1);strcpy(Document-elemcurline.base,s);printdoc(int startfileline,int startscrline)int i;int j;cursor_hide();i=startscrline;j=startfileline;setscrcolor(BLUE,YELLOW);gotoxy(
4、editwinx,editwiny+startscrline);while(ilength)clearscrline(editwinx,editwiny+i,78);putsxy(editwinx,editwiny+i+,Document-elemj+ -1.base);while(ilength;i+)free(Document-elemi.base);SequListDestroy(Document);readdoc(FILE *fp)char *newline;char s20000;int linenum=0;struct line curline;if(!fp) return;whi
5、le(!feof(fp)getline(fp,s);linenum+;newline=(char *)malloc(strlen(s)+1);strcpy(newline,s);curline.base=newline;curline.charnum=strlen(newline);SequListInsert(Document,linenum,curline);char ascii(int k)char c;c=(k8;if(c=32i-)si=si-1;si=c;deletechar(char *s,int pos)int i;int j;j=strlen(s);for(i=pos;i0)
6、cureditline-;gotoxy(editwinx,editwiny+cureditline);editline(cureditline,78);break;case KEYDown:if (cureditlinelength-1)cureditline+;gotoxy(editwinx,editwiny+cureditline);editline(cureditline,78);break;case KEYCtrl_y:deleteline(cureditline+1);if(Document-length=0)insertnewline(cureditline+1);if(cured
7、itline=Document-length)insertnewline(cureditline+1);printdoc(cureditline+1,cureditline-curscrtopline);gotoxy(editwinx,editwiny+cureditline);editline(cureditline,78);break;case KEYLeft:case KEYRight:break;case KEYCtrl_s:break;case ESC:cursor_hide();dofunc(getmenuitem();break;case KEYAlt_x:mainover=1;break;default:gotoxy(editwinx,editwiny+cureditline-curscrtopline);editline(cureditline,78);break;closedoc(curfile);setscrcolor(BLACK,WHITE);clrscr();cursor_show();