C语言课程设计简单的行编辑器文档格式.docx

上传人:b****6 文档编号:20166509 上传时间:2023-01-17 格式:DOCX 页数:22 大小:258.30KB
下载 相关 举报
C语言课程设计简单的行编辑器文档格式.docx_第1页
第1页 / 共22页
C语言课程设计简单的行编辑器文档格式.docx_第2页
第2页 / 共22页
C语言课程设计简单的行编辑器文档格式.docx_第3页
第3页 / 共22页
C语言课程设计简单的行编辑器文档格式.docx_第4页
第4页 / 共22页
C语言课程设计简单的行编辑器文档格式.docx_第5页
第5页 / 共22页
点击查看更多>>
下载资源
资源描述

C语言课程设计简单的行编辑器文档格式.docx

《C语言课程设计简单的行编辑器文档格式.docx》由会员分享,可在线阅读,更多相关《C语言课程设计简单的行编辑器文档格式.docx(22页珍藏版)》请在冰豆网上搜索。

C语言课程设计简单的行编辑器文档格式.docx

/*********************************主函数**************************************/

main()

{FILE*pfile;

pfile=fopen("

Linedit.txt"

"

a+"

);

readfile(lines,pfile);

fclose(pfile);

menu(lines);

}

intreadfile(char(*lines)[MAXC],FILE*pfile){

inti=0;

while(!

feof(pfile)){

fgets(lines[i],MAXC,pfile);

/*if(!

strstr(lines[i],"

\n"

))return1;

*/

i++;

return0;

2.主菜单函数

voidmenu(char(*lines)[MAXC]){

intselection;

do{

system("

cls"

puts("

\t\t***********************MUNU******************\n\n"

\t\t1.Editnewline"

\t\t2.Replaceline"

\t\t3.Deleteline"

\t\t4.Searchline"

\t\t5.Modifydata"

\t\t6.Save"

\t\t0.Exit"

\n\n\t\t********************************************\n"

printf("

Pleaseselectanumber:

[]\b\b"

scanf("

%d"

&

selection);

if(selection<

0||selection>

6){

Invalidselection!

Pleasetryagain"

andselectanumber:

[]\b\b\n"

elsebreak;

}while(true);

switch(selection)

{

case1:

edit(lines);

break;

case5:

modify(lines);

case3:

mydelete(lines);

case4:

search(lines);

case2:

replace(lines);

case6:

savetofile(lines);

case0:

myexit(lines);

}while(true);

3.各功能模块设计

(1)编辑模块

/*****************************编辑*************************************/

voidedit(char(*lines)[MAXC])

inti,index;

/*system("

clrscr();

for(i=0,index=0;

i<

MAXL;

i++)

if(lines[i][0]!

=0)

{

index++;

printf("

%d:

%s"

index,lines[i]);

}

\n\nPleasetypeanewline:

fflush(stdin);

for(i=0;

{

if(lines[i][0]=='

\0'

{/*每行第一个字符作为标志位空行可写入*/

fgets(lines[i],MAXC,stdin);

return;

else

continue;

(2)替换模块

/******************************替换****************************************/

voidreplace(char(*lines)[MAXC])

inti;

intindline;

intj,k;

do

*/

/*打印所有*/

i+1,lines[i]);

\n\nWhichlinedoyouprefertoreplace?

(Toquitpleaseinput0)[]\b\b"

scanf("

indline);

if(indline==0)

else

for(j=0,k=0;

j<

j++)

if(lines[j][0]!

=0)k++;

if(k==indline)

\n\nThelinetobereplacedis:

\n%s"

lines[j]);

Pleasetypeyournewline:

memset(lines[j],0,MAXC);

fgets(lines[j],MAXC,stdin);

break;

}

}while(true);

(3)删除模块

删除即在查找到某行的基础上再删掉,其具体流程图可参照查找的流程图

/*******************************删除***************************************/

voidmydelete(char(*lines)[MAXC])

\n\nWhichlinedoyouprefertodelete?

if(indline==0)return;

Thelinetobedeletedis:

\n%s\n"

system("

pause"

(4)查找模块

/**************************查找****************************************/

voidsearch(char(*lines)[MAXC])

\n\nWhichlinedoyouwanttosearch?

Thelinetobesearchedis:

(5)修改模块

删除模块的流程图也是在查找模块的基础上稍加改动,在此不再赘述

其流程图可简单写为

/******************************修改**********************************/

/*在sSrc中用sReplaceStr替换sMatchStr*/

intmodifystr(char*sSrc,char*sMatchStr,char*sReplaceStr)

intStringLen;

charcaNewString[MAXC];

char*FindPos=strstr(sSrc,sMatchStr);

if((!

FindPos)||(!

sMatchStr))

return-1;

while(FindPos)

memset(caNewString,0,sizeof(caNewString));

StringLen=FindPos-sSrc;

strncpy(caNewString,sSrc,StringLen);

strcat(caNewString,sReplaceStr);

strcat(caNewString,FindPos+strlen(sMatchStr));

strcpy(sSrc,caNewString);

FindPos=strstr(sSrc,sMatchStr);

return0;

voidmodify(char(*lines)[MAXC])

inti,indline;

charbuf[MAXC];

intk;

intj;

char*token=0;

charsearch[MAXC],replace[MAXC];

do

='

\n\nWhichlinedoyouprefertomodify?

\n\nInputthesearchstringandthereplace"

(Toquitpleaseinputq):

"

memset(buf,0,MAXC);

fgets(buf,MAXC,stdin);

k=strlen(buf)-1;

if(buf[k]=='

\n'

)buf[k]='

;

if(*buf=='

q'

&

*(buf+1)=='

)return;

memset(search,0,MAXC);

memset(replace,0,MAXC);

token=strtok(buf,"

"

strcpy(search,token);

token=strtok(NULL,"

strcpy(replace,token);

modifystr(lines[j],search,replace);

(6)保存模块

voidsavetofile(char(*lines)[MAXC])

FILE*pfile;

w+"

fputs(lines[i],pfile);

\nThelineshasbeensaved.\n"

(7)退出模块

voidmyexit(char(*lines)[MAXC])

charc;

Savethelinestothefile?

(y/n)"

c=getchar();

if(c=='

n'

)exit

(1);

savetofile(lines);

exit

(1);

五.上机操作

1.主菜单函数

2.编辑模块

3.替换模块

4查找模块.

5.修改模块

6.删除模块

7.保存模块

8.退出模块

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

当前位置:首页 > 幼儿教育 > 幼儿读物

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

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