c语言课设实验报告记事本程序含源码.docx

上传人:b****5 文档编号:7264043 上传时间:2023-01-22 格式:DOCX 页数:23 大小:22.20KB
下载 相关 举报
c语言课设实验报告记事本程序含源码.docx_第1页
第1页 / 共23页
c语言课设实验报告记事本程序含源码.docx_第2页
第2页 / 共23页
c语言课设实验报告记事本程序含源码.docx_第3页
第3页 / 共23页
c语言课设实验报告记事本程序含源码.docx_第4页
第4页 / 共23页
c语言课设实验报告记事本程序含源码.docx_第5页
第5页 / 共23页
点击查看更多>>
下载资源
资源描述

c语言课设实验报告记事本程序含源码.docx

《c语言课设实验报告记事本程序含源码.docx》由会员分享,可在线阅读,更多相关《c语言课设实验报告记事本程序含源码.docx(23页珍藏版)》请在冰豆网上搜索。

c语言课设实验报告记事本程序含源码.docx

c语言课设实验报告记事本程序含源码

C语言课设实验报告

[记事本程序]

班级:

学号:

姓名:

指导老师:

2012.9.3-2012.9.24

C语言课设实验报告

题目:

编写一个记事本程序。

设计要求:

1、记录要做的事,到设定的时间后弹出对话框提醒。

2、能实现编辑、保存、另存为、查找替换等功能。

3、提示:

使用文件输入输出流,定时器。

课设过程:

拿到题目时,还没有一个大概的设计思路。

当看完file,menu,graphic的程序代码之后,有了大致的代码结构:

1、先做好一个菜单的界面2、file的子菜单及其功能(新建,打开,保存,另存为,退出)的实现3、edit子菜单(查找,替换,定时)及其功能的实现。

基本框架做好后,再写各个功能的函数,写好后将其插到主函数中。

因为各个功能互不影响,其中还涉及到功能函数之间的嵌套,还有功能的子函数的位置。

在课设过程中遇到的第一个问题是输入内容的存放。

在file例子中是用结构体来存放输入内容,一开始,我想用一个字符串数组来存放,但文件内容写入的时候写入失败,文件可以建立,但打开后里面没有内容。

我觉得是fwrite()函数中的各个参数有问题,fwrite括号中的参数为(w(已定义的用来存放输入内容的字符串数组名),strlen(w[2000]),1,fp),于是就换成了一个普通的指针来存放,但还是行不通。

之所以不用像file中的结构体那样来存放数据,是因为如果用结构体,那结构体中就只有一个元素,且也元素必是一个字符串数组或是指针,为了更简洁一点,就排除了用结构体这个想法。

虽然输入的内容写不进所建立的文件中,但不会影响其他功能函数的编写。

在写完输入,文件的建立和内容的写入函数后,接着就是输入内容的保存和另存为,这两个功能差不多,只是文件名不同。

因为在创建文件程序块里文件名是程序员自己命名好了的,并且只能建立一个,每次输入的内容会把上次输入的文件内容覆盖。

所以我想由用户自己给文件命名,文件名是用一个字符串数组来存放,猜想建立文件的函数为fp=fopen("c:

\%s.txt",s(存放文件名的数组名),''ab+"),但运行报错,猜想不可行,于是向老师请教了这个问题,经老师指导,用指针来存放文件名,fp=(s,"ab+"),输入文件名时得要按某盘根录下+某文件夹下+文件名的形式输入。

编到这儿,file子菜单的功能就完成了,接下来就是edit子菜单功能函数的编写。

但因为不知道key_alt_e的扫描码,在网上也搜索不到,课设老师也不太记得了,说用bioskey函数把这个值输出来,但是程序编写好后,输出的值不稳定,且不是十进制数值,于是就向其他的老师需求帮助,在老师的帮助下,知道了key_alt_e的扫描码,于是可以打开edit子菜单功能。

但在这个过程中又遇到了edit子菜单窗口的问题,通过不断改变window(),box(),gotoxy()函数中参数的数值,一次一次运行调试,查看是否到位,是否美观,最后才把把值确定。

edit子菜单中查找和替换功能要繁琐,就没编译。

程序大致也编译完成了,功能都可以实现,但是还是文件写入的问题,文件打开后,里面没有任何内容,实为系统问题,程序无任何语法错误,但程序的功能可以运行。

代码及注释:

#include

#include

#include

#include

#include

#include

#definekey_down80

#definekey_up72

#definekey_esc1

#definekey_alt_f33

#definekey_alt_x45

#definekey_enter28

#definekey_alt_e18

intget_key();

voidbox(intstartx,intstary,inthigh,intwidth);

{

inti,key,x,y,l;

char*w=NULL,*d=NULL,*s=NULL;

FILE*fp;

char*menu[]={"File","Edit","Format","View","Help"};

char*red[]={"F","E","F","V","H"};

char*f[]={"New","Open","Save","Another","Quitalt_x"};

char*e[]={"Search","Searchnext","Replace","Date"};

charbuf[16*10*2],buf1[16*2];

textbackground(3);

clrscr();

window(1,1,80,1);

textbackground(WHITE);

textcolor(BLUE);

clrscr();

window(1,1,80,2);

for(i=0,l=0;i<5;i++)

{

x=wherex();

y=wherey();

textcolor(BLACK);

cprintf("%s",menu[i]);

l=strlen(menu[i]);

gotoxy(x,y);

textcolor(RED);

cprintf("%s",red[i]);

x=x+l+4;

gotoxy(x,y);

}

printf("\n");

printf("Youcantakeyournotenow\n");

gets(w);

printf("kkk%s",w);

while

(1)

{

key=0;

while(bioskey

(1)==0)

{

key=get_key();

if(key==key_alt_e)

{

textbackground(BLACK);

textcolor(WHITE);

gotoxy(12,1);

cprintf("%s",menu[1]);

gettext(4,2,25,8,buf);

window(12,2,25,6);

textbackground(WHITE);

textcolor(BLACK);

clrscr();

window(12,2,25,9);

box(1,1,6,14);

for(i=2;i<6;i++)

{

gotoxy(2,i);

cprintf("%s",e[i-2]);

}

gettext(2,2,18,3,buf1);

textbackground(0);

textcolor(15);

gotoxy(2,2);

cprintf("%s",e[0]);

y=2;

key=get_key();

while(key!

=key_alt_e&&key!

=key_enter&&key!

=key_esc)

{

if(key==key_up||key==key_down)

{

puttext(2,y,32,y+1,buf1);

if(key==key_up)

y=y==2?

5:

y-1;

if(key==key_down)

y=y==5?

2:

y+1;

gettext(2,y,32,y+1,buf1);

textbackground(0);

textcolor(15);

gotoxy(2,y);

cprintf("%s",e[y-2]);

}

key=get_key();

}

if(key==key_alt_x)

exit(0);

if(key==key_enter)

{

switch(y-1)

{

case1:

window(1,2,80,25);

textbackground(YELLOW);

clrscr();

/*Search();*/

break;

case2:

window(1,2,80,25);

textbackground(YELLOW);

clrscr();

/*Search_next();*/

break;

case3:

window(1,2,80,12);

textbackground(YELLOW);

clrscr();

/*Replace();*/

break;

case4:

window(1,2,80,25);

textbackground(YELLOW);

clrscr();

fp=fopen(d,"rb+");

if(fp==NULL)

printf("Notexist!

");

else

{

printf("Inputthefiletodate;");

scanf("%s",d);

fp=fopen(d,"rb+");

if(fp==NULL)

printf("Notexist!

");

else

{

printf("Enterthetimeofreminding:

");

scanf("%ld",&t);

rewind(fp);

delay(t);

fread(w,strlen(*w),1,fp);

printf("%s",*w);

}

}

break;

default:

break;

}

}

else

{

window(1,1,80,2);

puttext(4,2,25,8,buf);

textbackground(WHITE);

textcolor(BLACK);

gotoxy(21,1);

cprintf("%s",menu[2]);

}

}

if(key==key_alt_x)

exit(0);

if(key==key_alt_f)

{

textbackground(BLACK);

textcolor(WHITE);

gotoxy(4,1);

cprintf("%s",menu[0]);

gettext(4,2,18,12,buf);

window(4,2,17,7);

textbackground(WHITE);

textcolor(BLACK);

clrscr();

window(4,2,20,10);

box(1,1,7,14);

for(i=2;i<7;i++)

{

gotoxy(2,i);

cprintf("%s",f[i-2]);

}

gettext(2,2,18,3,buf1);

textbackground(0);

textcolor(15);

gotoxy(2,2);

cprintf("%s",f[0]);

y=2;

key=get_key();

while(key!

=key_alt_x&&key!

=key_enter&&key!

=key_esc)

{

if(key==key_up||key==key_down)

{

puttext(2,y,18,y+1,buf1);

if(key==key_up)

y=y==2?

6:

y-1;

if(key==key_down)

y=y==6?

2:

y+1;

gettext(2,y,18,y+1,buf1);

textbackground(0);

textcolor(15);

gotoxy(2,y);

cprintf("%s",f[y-2]);

}

key=get_key();

}

if(key==key_alt_x)

exit(0);

if(key==key_enter)

{

switch(y-1)

{

case1:

window(1,2,80,25);

textbackground(YELLOW);

clrscr();

printf("Youcantakeyournotenow:

\n");

scanf("%s",w);

break;

case2:

window(1,2,80,25);

textbackground

(2);

clrscr();

printf("Pleaseinputthefileyouwanttoopen:

");

scanf("%s",s);

fp=fopen(s,"r+");

if(fp==NULL)

printf("Notexist!

");

else

rewind(fp);

fread(w,strlen(*w),1,fp);

printf("%s",*w);

break;

case3:

window(1,2,80,25);

textbackground(BLUE);

clrscr();

printf("qqq%s\n",w);

save(w);

break;

case4:

window(1,2,80,25);

textbackground(BLUE);

clrscr();

Another(w);break;

case5:

exit(0);

default:

break;

}

}

else

{

window(1,1,80,2);

puttext(4,2,19,10,buf);

textbackground(WHITE);

textcolor(BLACK);

gotoxy(4,1);

cprintf("%s",menu[0]);

}

}

}

}

}

intget_key()

{

unionREGSrg;

rg.h.ah=0;

int86(0x16,&rg,&rg);

returnrg.h.ah;

}

voidbox(intstartx,intstarty,inthigh,intwidth)

{

inti;

gotoxy(startx,starty);

putch(0xda);

for(i=startx+1;i

putch(0xc4);

putch(0xbf);

for(i=starty+1;i

{

gotoxy(startx,i);

putch(0xb3);

gotoxy(width,i);

putch(0xb3);

}

gotoxy(startx,starty+high-1);

putch(0xc0);

gotoxy(startx+1,starty+high-1);

for(i=startx+1;i

putch(0xc4);

putch(0xd9);

return;

}

intrenew_interface()

{

inti,key,x,y,l;

char*w=NULL;

char*d=NULL,*s=NULL;

FILE*fp;

char*menu[]={"File","Edit","Search"};

char*red[]={"F","E","S"};

char*f[]={"NEW","Open","Save","Another",

"Quitalt_x"};

char*e[]={"Search","Searchnext","Replace","Date"};

charbuf[16*10*2],buf1[16*2];

textbackground(3);

clrscr();

window(1,1,80,1);

textbackground(WHITE);

textcolor(BLUE);

clrscr();

window(1,1,80,2);

for(i=0,l=0;i<3;i++)

{

x=wherex();

y=wherey();

printf("%s",menu[i]);

l=strlen(menu[i]);

gotoxy(x,y);

textcolor(BLUE);

cprintf("%s",red[i]);

x=x+l+4;

gotoxy(x,y);

textcolor(BLACK);

}

printf("\n");

printf("Youcantakeyournotenow:

\n");

scanf("%s",w);

while

(1)

{

key=0;

while(bioskey

(1)==0);

key=get_key();

if(key==key_alt_e)

{

textbackground(BLACK);

textcolor(WHITE);

gotoxy(12,1);

cprintf("%s",menu[1]);

gettext(4,2,25,8,buf);

window(12,2,25,6);

textbackground(WHITE);

textcolor(BLACK);

clrscr();

window(12,2,25,9);

box(1,1,6,14);

for(i=2;i<6;i++)

{

gotoxy(2,i);

cprintf("%s",e[i-2]);

}

gettext(2,2,18,3,buf1);

textbackground(0);

textcolor(15);

gotoxy(2,2);

cprintf("%s",e[0]);

y=2;

key=get_key();

while(key!

=key_alt_e&&key!

=key_enter&&key!

=key_esc)

{

if(key==key_up||key==key_down)

{

puttext(2,y,32,y+1,buf1);

if(key==key_up)

y=y==2?

5:

y-1;

if(key==key_down)

y=y==5?

2:

y+1;

gettext(2,y,32,y+1,buf1);

textbackground(0);

textcolor(15);

gotoxy(2,y);

cprintf("%s",e[y-2]);

}

key=get_key();

}

if(key==key_alt_x)

exit(0);

if(key==key_enter)

{

switch(y-1)

{

case0:

window(1,2,80,25);

textbackground(YELLOW);

clrscr();

/*Search();*/

break;

case1:

window(1,2,80,25);

textbackground(YELLOW);

clrscr();

/*Search_next();*/

break;

case2:

/*window(1,2,80,12);

textbackground(YELLOW);

clrscr();

Replace();*/

break;

case3:

window(1,2,80,25);

textbackground(YELLOW);

clrscr();

fp=fopen(d,"rb+");

if(fp==NULL)

printf("Notexist!

");

else

{

printf("Inputthefiletodate;");

scanf("%s",d);

fp=fopen(d,"rb+");

if(fp==NULL)

printf("Notexist!

");

else

{

printf("Enterthetimeofreminding:

");

scanf("%ld",&t);

rewind(fp);

delay(t);

fread(w,strlen(*w),1,fp);

printf("%s",*w);

}

}break;

default:

break;

}

}

else

{

window(1,1,80,2);

puttext(4,2,25,8,buf);

textbackground(WHITE);

textcolor(BLACK);

gotoxy(21,1);

cprintf("%s",menu[2]);

}

}

if(key==key_alt_x)

exit(0);

if(key==key_alt_f)

{

textbackground(0);

textcolor(15);

gotoxy(4,1);

cprintf("%s",menu[0]);

gettext(4,2,18,12,buf);

window(4,2,20,10);

textbackground(15);

textcolor(0);

clrscr();

window(4,2,20,10);

box(1,1,8,20);

for(i=2;i<7;i++)

{

gotoxy(2,i);

printf("%s",f[i-2]);

}

gettext(2,2,18,3,buf1);

textbackground

(2);

textcolor(15);

gotoxy(2,2);

cprintf("%s",f[0]);

y=2;

key=get_key();

while(key!

=key_alt_x&&key!

=key_enter&&key!

=key_esc)

{

if(key==key_up||key==key_down)

{

puttext(2,y,18,y+1,buf1);

if(key==key_up)

y=y==2?

6:

y-1;

if(key==key_down)

y=y==6?

2:

y+1;

gettext(2,y,18,y+1,buf1);

textbackground(0);

textcolor(15);

gotoxy(2,y);

cprintf("%s",f[y-2]);

}

key=get_key();

}

if(key==key_alt_x)

exit(0);

if(key=

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 党团工作 > 入党转正申请

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1