📄 gyh.txt
字号:
/* Copyright @2005 gao */
/* Apr.10.2005 */
/* num:1102101507 name:gaoyonghong */
#include <conio.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dir.h>
#include <dos.h>
#define F1KEY 59
#define F2KEY 60
#define F3KEY 61
#define F4KEY 62
#define F5KEY 63
#define LEFT0 75
#define RIGHT0 77
#define UP0 72
#define DOWN0 80
#define PGDN0 81
#define PGUP0 73
#define DEL0 83
#define INS0 82
#define HOME0 71
#define END0 79
#define BKSP 8
#define ENTER 13
/*/////////////////////////////////////////*/
typedef struct
{
char tt[80];
}tr;
tr rr[50];
char *fnm;
char fname[30]="newfile.txt",
ins=1;
int fh,fl=0;
/*/////////////////////////////////////////*/
void welcome()
{ /*显示欢迎界面,“哪哪哪”DOS下是直线。*/
clrscr();
gotoxy(10,3);
puts(" NAME :gaoyonghong NUMBER : 000000 ");
gotoxy(10,5);
puts("谀哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪目");
gotoxy(10,6);
puts(" Welcome to use my Editor ! " );
gotoxy(10,7);
puts(" ");
gotoxy(10,8);
puts(" SYSTEM : MS-DOS ");
gotoxy(10,9);
puts(" FILENAME : 000000.cpp ");
gotoxy(10,10);
puts(" ");
gotoxy(10,11);
puts(" Information : newfile,openfile,savebak, ");
gotoxy(10,12);
puts(" savefile,exit. ");
gotoxy(10,13);
puts("滥哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪馁");
gotoxy(1,16);
puts("Press Enter...");
gotoxy(15,16);
getch();
}
/*/////////////////////////////////////////*/
void dspbox()
{ /*提示方框*/
gotoxy(21,10); puts("谀哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪目");
gotoxy(21,11); puts(" ");
gotoxy(21,12); puts("滥哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪哪馁");
return;
}
/*/////////////////////////////////////////*/
void clsbox()
{ /*清除提示方框*/
int i,j;
gotoxy(2,10);
for(i=8; i<12; i++)
for(j=1; j<81; j++)
printf("%c",rr[i].tt[j]);
}
/*/////////////////////////////////////////*/
void cut()
{ /*限制*/
if(fl<0)
{
fh--;fl=78;
}
if(fh<0)
{
fl=0;fh=0;
}
if(fl>78)
{
fh++;fl=0;
}
if(fh>22)
{
fh=22;fl=78;
}
}
/*/////////////////////////////////////////*/
void left()
{ /*处理左键*/
fl--;
if(fl<0) fl=0;
}
/*/////////////////////////////////////////*/
void right()
{ /*处理右键*/
fl++;
if(fl>78) fl=78;
}
/*/////////////////////////////////////////*/
void up()
{ /*处理上键*/
fh--;
if(fh<0) fh=0;
}
/*/////////////////////////////////////////*/
void down()
{ /*处理下键*/
fh++;
if(fh>22) fh=22;
}
/*/////////////////////////////////////////*/
void delch()
{ /* 处理del键*/
rr[fh].tt[fl]=' ';
cputs(" ");
}
/*/////////////////////////////////////////*/
void bkspch()
{ /* 处理BackSpace键*/
rr[fh].tt[fl]=' ';
cputs(" ");
fl--;
cut();
}
/*/////////////////////////////////////////*/
void enter()
{ /* 处理Enter键*/
int i;
fl=0;
fh++;
cut();
}
/*/////////////////////////////////////////*/
void newfile()
{ /*新建*/
int i,j;
clrscr();
textattr(18);
cputs(" F1:New F2:Open F3:Savebak F4:Save F5:Exit");
gotoxy(1,1);
cprintf("newfile.txt");
textattr(28);
textattr(28);
gotoxy(1,25);
cprintf("%4d :%2d",fh+1,fl+1);
textattr(7);
gotoxy(1,2);
for(i=0; i<24; i++)
{
for(j=0; j<80; j++)
{
rr[i].tt[j]=' ';
}
}
}
/*/////////////////////////////////////////*/
readfile()
{ /*打开*/
FILE *f1;
char ch;
int i,j=1;
gotoxy(25,11);
printf("Please input file name: .txt");
gotoxy(48,11);
fnm=cgets(fname);
strcat(fnm,".txt");
if((f1=fopen(fnm,"rt"))==NULL) return -1;
gotoxy(1,2);
ch=fgetc(f1);
while(ch!=EOF)
{
putchar(ch);
if(ch!='\n')
{
rr[i].tt[j]=ch;
j++;
}
else
{
i++;
j=1;
}
ch=fgetc(f1);
}
fclose(f1);
textattr(18);
gotoxy(1,1);
cputs(" F1:New F2:Open F3:Savebak F4:Save F5:Exit");
gotoxy(1,1);
printf(" ");
gotoxy(1,1);
printf(fname);
textattr(7);
gotoxy(1,2);
return 0;
}
/*/////////////////////////////////////////*/
void savebak()
{
int i,j;
FILE *fp;
textattr(28);
gotoxy(1,1);
printf("newfile.txt & !file.bak");
fp=fopen("!file.bak","wt");
for(i=0; i<24; i++)
{
for(j=0; j<80; j++)
{
fputc(rr[i].tt[j],fp);
}
fprintf(fp,"\n");
}
}
/*/////////////////////////////////////////*/
void savefile()
{ /* 保存*/
int i,j;
FILE *fp;
gotoxy(25,11);
printf("Please input file name: .txt");
gotoxy(48,11);
fnm=cgets(fname);
strcat(fnm,".txt");
fp=fopen(fnm,"wt");
for(i=0; i<24; i++)
{
for(j=0; j<80; j++)
{
fputc(rr[i].tt[j],fp);
}
fprintf(fp,"\n");
}
textattr(28);
gotoxy(1,1);
printf(" ");
gotoxy(1,1);
cprintf(fname);
textattr(28);
}
/*/////////////////////////////////////////*/
void savechars(unsigned char ch)
{ /*键入保存*/
rr[fh].tt[fl]=ch;
}
/*/////////////////////////////////////////*/
void handch(unsigned char ch)
{ /*键入打印*/
int i;
if(ins)
{
cprintf("%c",ch);
fl++;
cut();
}
else
{
putch(ch);
fl++;
cut();
}
}
/*/////////////////////////////////////////*/
void F1()
{ /*new*/
newfile();
dspbox();
gotoxy(25,11);
printf("New file is OK ! ...");
getch();
clsbox();
}
/*/////////////////////////////////////////*/
void F2()
{ /*open*/
dspbox();
readfile();
clsbox();
}
/*/////////////////////////////////////////*/
void F3()
{ /*savebak*/
savebak();
dspbox();
gotoxy(25,11);
printf("Save bak is OK ! ...");
getch();
clsbox();
}
/*/////////////////////////////////////////*/
void F4()
{ /*save*/
dspbox();
gotoxy(25,11);
printf("Save OK? Press any key...");
getch();
savefile();
clsbox();
}
/*/////////////////////////////////////////*/
void F5()
{ /*exit*/
dspbox();
gotoxy(25,11);
printf("Exit OK? Press any key...");
getch();
fcloseall(); /*关闭所有文件*/
exit(0);
}
/*//////////////////////////main///////////////////////////*/
main()
{ /*主函数*/
unsigned char ch;
welcome();
clrscr();
textattr(18);
cputs(" F1:New F2:Open F3:Savebak F4:Save F5:Exit");
gotoxy(1,1);
cprintf(fname);
textattr(28);
while(1)
{
textattr(28);
gotoxy(1,25);
cprintf("%4d :%2d",fh+1,fl+1);
textattr(7);
gotoxy(fl+1,fh+2);
ch=getch();
switch(ch)
{
case 0:
if(kbhit())
{
ch=getch();
switch(ch)
{
case LEFT0: left(); break;
case RIGHT0: right(); break;
case UP0: up(); break;
case DOWN0: down(); break;
case PGDN0: fh=22; break;
case PGUP0: fh=0; break;
case HOME0: fl=0; break;
case END0: fl=78; break;
case DEL0: delch(); break;
case INS0: ins=ins?0:1;
/* _setcursortype(ins?_NORMALCURSOR:_SOLIDCURSOR); */
break;
case F1KEY: F1(); break; /*new*/
case F2KEY: F2(); break; /*open*/
case F3KEY: F3(); break; /*savebak*/
case F4KEY: F4(); break; /*save*/
case F5KEY: F5(); break; /*exit*/
default: fl;
}
} break;
case BKSP: bkspch(); break;
case ENTER: enter(); break;
default: savechars(ch);
if(ch<32 || ch>254 ) break;
handch(ch);
}
}
}
/*//////////////////////////main end///////////////////////*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -