我写了一个汉字行编辑程序,请各位多多指教,找出本程序的不足,以提高本程序的功能,!
程序如下:
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
#include "conio.h"
#define len 4
#define LINESIZE 80 /*每行长度为80个字符*/
strUCt TEXT
{
struct TEXT *prior;
char str[LINESIZE+1]; /*包括 '\0' 在内,设置长度为LINESIZE+1*/
struct TEXT *next;
};
struct TEXT *TPTR,*BPTR,*KPTR,*QPTR,*SPTR,*YPTR,*XPTR,*FPTR;
struct TEXT *ptr,*work;
int CHG,ERR,CMP,IND,CTR,i,NUM;
char ch,BUF;
char IN[LINESIZE+1],NUMD[len],MAT[LINESIZE],REP[LINESIZE],temp[LINESIZE];
void main() /*#1 主要起调度作用*/
{
void IN99v();
void READ_LINE();
void INPUT();
void TOP();
void UP();
void NEXT();
void ENTER();
void LIST();
void DELETE();
void REPLACE();
void FIND();
void INSERT();
void COPY();
void STORE();
void WR99vE_LINE();
clrscr();
IN99v();
while(1)
{
if(IND==0)
printf("\n-"); /*命令提示符*/
READ_LINE();
i=0;
if(IND!=0)
INPUT();
else
{
ch=IN[0];
if(ch=='T'ch=='t')
TOP();
else if(ch=='U'ch=='u')
UP();
else if(ch=='N'ch=='n')
NEXT();
else if(ch=='E'ch=='e')
ENTER();
else if(ch=='L'ch=='l')
LIST();
else if(ch=='D'ch=='d')
DELETE();
else if(ch=='R'ch=='r')
REPLACE();
else if(ch=='F'ch=='f')
FIND();
else if(ch=='I'ch=='i')
INSERT();
else if(ch=='C'ch=='c')
COPY();
else if(ch=='S'ch=='s')
STORE();
else if(ch=='Q'ch=='q')
exit(0);
else
{
strcpy(IN,"?!\0"); /*不正确的编辑命令响应*/
WR99vE_LINE();
}
}
}
}
void IN99v() /*#2 初始化正文编辑程序*/
{
void WR99vE_LINE();
printf("\n ________________________________________");
printf("\n program for edit ");
printf("\n T:TOP U N:UP N N:NEXT ");
printf("\n E:ENTER L N:LIST D N:DELETE ");
printf("\n R /STR1/STR2/ N:REPLACE F /SFTR1/:FIND ");
printf("\n C N:COPY S N:STORE I:INSERT ");
printf("\n Q:QU99v -: the sing of order ");
printf("\n -----------------------------------------");
FPTR=(struct TEXT*)malloc(sizeof(struct TEXT));
FPTR->prior=0;
FPTR->next=0;
CMP=CHG=ERR=0;
IND=0;
BPTR=TPTR=0; /*无正文链*/
KPTR=QPTR=0; /*无工作链*/
strcpy(IN,"ED99v!\0");
WR99vE_LINE();
}
void READ_LINE() /*#3 从终端接收一行正文并且把它存到缓冲器IN中 */
{
i=0;
BUF=getchar();
while(i<LINESIZE && BUF!='\n')
{
if(BUF=='@')
{
if(i!=0)
{
if(IN[i-1]<0)
{
IN[--i]=' '; /*是汉字删掉两个字节*/
IN[--i]=' ';
}
else
IN[--i]=' '; /*不是汉字删掉一个字节*/
}
}
if(BUF=='#')
i=0;
if(BUF<0)
{
IN[i++]=BUF;
IN[i++]=getchar();
}
else
if(BUF!='@' && BUF!='#')
IN[i++]=BUF;
BUF=getchar();
}
if(i>=LINESIZEBUF=='\n')
{