Home > Back-end >  Amend the code can run on the visual c 2010, void beep () there will be the speaker, delay of 100 se
Amend the code can run on the visual c 2010, void beep () there will be the speaker, delay of 100 se

Time:09-21

# include
# include
# include
# include
# include
# include
# include
# define MAXROW 300
# define MAXCOL 80
# define MAXCMDTIMES 300
# define BackSpace 8
# define CR 13
# define ESC 277
# define UP 72
# define PGUP 73
# define LEFT 75
# define RIGHT 77
# define DOWN 80
# define PGDN 81
# define CTRL_B 2
# define CTRL_F 6
# define MIN (a, b) a> b? B:
# define MAX (a, b) a> b? A: b

Void beep (void);
Int init (char *);
Int editfun (char *);
Void beep (void);
Int write_file (char *);
Void refresh_scr (void);
Int input_str (int, int, char *, int).
Int the display (int, char *);
Int append (void);
Int search (char *);

Typedef struct {
Int allrec;
Int scry;
Int shinex shiney;
Unsigned char info [MAXROW] [MAXCOL + 1];
} EDIT;
EDIT EDIT;
Void main (int arg c, char * argv [])
{
If (arg c!=2) {
Printf (" Command error! Filename \ nUsage % s \ n ", argv [0]);
return;
}
If (init (argv [1]) <0)
return;
Editfun (argv [1]);
CLRSCR ();
exit(0);
}

Int init (char * filename)
{
Int I, j;
The FILE * fp.
If ((fp=fopen (filename, "r"))==NULL) {
Printf (" the File % s is not exist! Create now! \ n ", filename);
If ((fp=fopen (filename, "w"))==NULL) {
Printf (" Can not create the file % s \ n ", filename);
return -1;
}
Fprintf (fp, "\ n");
The fclose (fp);
Fp=fopen (filename, "r");
}
Memset (edit. Info, 0, sizeof (edit. The info));
for(i=0; I The fgets (edit info [I], MAXCOL + 1, fp);
If (feof (fp))
break;
J=strlen (edit info [I]) - 1;
If (edit info [I] [j]=='\ n')
Edit the info [I] [j]='\ 0';
}
Edit. Allrec=I;
Edit. Scry=0;
Edit. Shinex=1;
Edit. Shiney=1;
The fclose (fp);
return 0;
}

Int editfun (char * filename)
{
Int editflag=0;
Int nr.
int i;
Int in_ch;
Int cmdtimes;
Int rolllines;
Int len.
Char command [81].
Char queryinfo [81].

Refresh_scr ();
Memset (queryinfo, 0, sizeof (queryinfo));
While (1) {
If (editflag==1 & & edit. Allrec==0)
Edit. Allrec=1;
If (edit) shiney + edit) scry> edit. Allrec)
Edit. Shiney=edit. Allrec - edit. Scry;
Nr=edit. Shiney - 1 + edit. Scry;
Len=strlen (edit info (nr));
If (edit. Shinex>=len + 1)
Edit. Shinex=(editflag==1 | | len==0)? Len + 1: len;
Gotoxy (edit shinex, edit. Shiney);
In_ch=getch ();
If (editflag) {
The switch (in_ch) {
In case the ESC:
Editflag=0;
If (edit. Shinex> 1)
Edit. Shinex -;
break;
Case BackSpace:
If (edit. Shinex> 1) {
For (I=edit. Shinex - 1; I Edit. Info [nr] [I]=edit. The info/nr [I + 1);
If (edit. Shinex> 1)
Edit. Shinex -;
Display (edit shiney, edit the info (nr));
}
break;
Case CR:
Append ();
break;
Default:
For (I=MAXCOL - 1; I>=edit. Shinex; I -)
Edit. Info [nr] [I]=edit. The info/nr [I - 1);
Edit. Info [nr] [I]=(unsigned char) in_ch;
If (edit. Shinex Edit. Shinex++;
Display (edit shiney, edit the info (nr));
break;
}
}
The else {
Memset (command, 0, sizeof (command));
Cmdtimes=1;
If (in_ch>='1' && in_ch <='9') {
for(i=0; In_ch>='0' && in_ch <='9'; I++) {
The command [I]=(char) in_ch;
In_ch=getch ();
}
Cmdtimes=atoi (command);
If (cmdtimes <=0 | | cmdtimes>=MAXCMDTIMES) {
Beep ();
continue;
}
}
If (in_ch==0)
In_ch=getch ();
The switch (in_ch) {
In case the 'I' :
Editflag=1;
break;
Case 'a' :
Edit. Shinex++;
Editflag=1;
break;
Case 'A' :
Edit. Shinex=len + 1;
Editflag=1;
break;
Case: 'o'
Append ();
Editflag=1;
break;
Case: ':'
Gotoxy (1, 25);
Clreol ();
Printf (" : ");
If (input_str (2, 25, command, sizeof (command) - 1)==0) {
If (STRCMP (command, "x")==0) {
Write_file (filename);
return 0;
}
If (STRCMP (command, "q")==0)
return 1;
If (STRCMP (command, "w")==0)
Write_file (filename);
}
break;
Case '/' :
Gotoxy (1, 25);
Clreol ();
Clreol ();
Printf ("/");
If (input_str (2, 25, command, sizeof (command) - 1)==0)
Strcpy (queryinfo, command);
The else
break;
Case 'n' :
If (search (queryinfo))
Beep ();
break;
Case 'x' :
If (len) {
If (cmdtimes> len - edit. Shinex + 1)
Cmdtimes=len - edit. Shinex + 1;
for(i=0; I Edit the info (nr)/edit. Shinex + I - 1=
Edit. The info/nr [edit shinex + I + cmdtimes - 1].
Memset (edit info/nr + len - cmdtimes, 0, cmdtimes);
Display (edit shiney, edit the info (nr));
}
The else
Beep ();
break;
Case 'd' :
In_ch=getch ();
If (in_ch=='d' & edit. Allrec> 0) {
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related