文本编辑《数据结构》上机实验报告(3)

2019-05-17 13:59

}

fclose(fp);

Hp=Hp->nextl;/*因为Hp的所在节点的数据域为空,所以Hp=Hp->nextl*/ return ; }

/*将head所指的行单链表中所指的各个列单链表中的数据域的值写入文件,文件路径和文件名由用户指定*/

void save(Hnode *head) {

FILE* fp; Hnode *q;

node *p;

char filename[10]; /*保存文件名*/ q=head;

clrscr();/*清屏*/

printf(\输入文件名格式*/ scanf(\输入文件名*/ fp=fopen(filename,\

if(fp==NULL) /*打开文件失败*/ {

}

printf(\getchar(); return ;

do{

p=q->next; /*指向node类型的数据*/

while(p!=NULL) {

if((int)p->ch==13)/*把回车转化为换行符*/

{

fputc('\\n',fp);

p=p->next;

} else {

fputc(p->ch, fp);

} } q=q->nextl; }while(q!=NULL);

fclose(fp); /*关闭此文件*/

return ;

p=p->next;

}

void main() { char a;

int i,A,x,y,flag=0,b,t; Hnode *Hhead,*q;

node *p1,*p2;

Hhead=q=(Hnode *)malloc(sizeof(Hnode)); /*为行单链表中首节点分配内存空间*/ q->nextl=NULL;

q->next=p1=p2=(node *)malloc(sizeof(node)); p1->ch=13; p1->next=NULL; while(1) {

while(bioskey(1)==0) continue; /*等待用户按键*/ a=A=bioskey(0); /*返回输入的字符的键值*/ if(a>=32&&a<127) /*若输入为常规字符*/ {

if(check(Hhead,wherey(),wherex())<=0)/*当前位置没有字符且输入是常规字符,

则执行添加字符操作*/ { p2->ch=a; putch(a);

if(wherex()-1==80) {

q->nextl=(Hnode *)malloc(sizeof(Hnode)); q=q->nextl; q->nextl=NULL; q->next=NULL;

p1=p2=q->next=(node *)malloc(sizeof(node)); p1->ch=13; p1->next=NULL;

} else {

p2->next=(node *)malloc(sizeof(node));

p2=p2->next; p2->ch=13; p2->next=NULL;

gotoxy(1,wherey()+1);

}

}

else /*当前位置有字符且输入是常规字符,则执行插入字符操作*/

x=wherex(); y=wherey();

insert(Hhead,wherey(),wherex(),a); view(Hhead); gotoxy(x+1,y);

{ }

}

列有字符*/

if(a==13) {

gotoxy(1,wherey()+1);

q->nextl=(Hnode *)malloc(sizeof(Hnode)); q=q->nextl;

q->nextl=NULL;

q->next=NULL;

p1=p2=q->next=(node *)malloc(sizeof(node)); p1->ch=13;

p1->next=NULL;

} x=wherex(); y=wherey();

/*文本窗口中左移,当前光标不在窗口的第1列*/ if((A==LEFT)&&(x!=1))

gotoxy(wherex()-1,wherey());

/*文本窗口中左移,当前光标在窗口的第1列*/ if((A==LEFT)&&(x==1))

gotoxy(abs(judge(Hhead,wherey()-1)),wherey()-1);

/*文本窗口中右移,若当前光标的右边一位有字符*/

if((A==RIGHT)&&check(Hhead,wherey(),wherex())>0)

gotoxy(wherex()+1,wherey());

/*文本窗口中右移至下行的第1列,若当前光标位置没有字符且下行的第1if((A==RIGHT)&&check(Hhead,wherey()+1,1)!=0&&check(Hhead,y,x)<=0) gotoxy(1,wherey()+1);

/*右移*/

if((A==RIGHT)&&x==80)

gotoxy(1,wherey()+1);

/*上移*/

if((A==UP)&&check(Hhead,wherey()-1,wherex())!=0)

gotoxy(wherex(),wherey()-1);

/*下移*/

if((A==DOWN)&&check(Hhead,wherey()+1,wherex())!=0) gotoxy(wherex(),wherey()+1); /*处理BackSpace键*/

if(A==BACK) /*处理BackSpace键*/ {

flag=del(Hhead,wherey(),wherex()-1); x=wherex()-1; y=wherey(); view(Hhead); if(flag==0) {

gotoxy(x,y);

}

if(flag==1) {

gotoxy(x+1,y); flag=0; } } /*处理Ctrl+x按键*/ /*处理Ctrl+x按键*/ if(A==Cx&&value!=0) {

if(value>0) { x=wherex();

y=wherey(); }

Else

{

x=r[0].col;

y=r[0].line; }

for(i=0;i

del(Hhead,r[i].line,r[i].col);

backup=value; /*保存r数组的有值元素的最大下标值*/ value=0; /*此value为全局变量*/ view(Hhead); gotoxy(x,y); }

/*处理Ctrl+c按键*/ if(A==Cc&&value!=0) {

x=wherex();

y=wherey();

backup=value; value=0; /*此value为全局变量*/ view(Hhead); gotoxy(x,y); }

/*处理Ctrl+v按键*/ if(A==Cv&&backup!=0) {

x=wherex();

y=wherey();

if(backup<0) /*Ctrl+右移键选定的文本,贴切此当前位置*/ for(i=0;i

insert(Hhead,y,x+i,r[i].ch);/*逐个插入*/ if(backup>0) /*Ctrl+左移键选定的文本,贴切此当前位置*/ for(i=0;i

insert(Hhead,y,x+i,r[backup-1-i].ch); view(Hhead); gotoxy(x,y);

}

/*处理Ctrl+左移键或右移键*/

if(A==CL||A==CR) control(A,Hhead); if(A==F1)

{

clrscr();/*清屏*/

main(); } /*新建文件*/

if(A==F3)

{ /*打开文件*/

Hhead=(Hnode *)malloc(sizeof(Hnode)); opens(Hhead); getchar();

clrscr();

view(Hhead);

}

/*保存文件*/

if(A==F2) {

save(Hhead); clrscr();

cprintf(\getch();

view(Hhead); }


文本编辑《数据结构》上机实验报告(3).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:用友通会计电算化考试实务题操作流程[1]

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: