c简易文本编辑器ttWord格式.docx

上传人:b****6 文档编号:18593139 上传时间:2022-12-28 格式:DOCX 页数:21 大小:18.88KB
下载 相关 举报
c简易文本编辑器ttWord格式.docx_第1页
第1页 / 共21页
c简易文本编辑器ttWord格式.docx_第2页
第2页 / 共21页
c简易文本编辑器ttWord格式.docx_第3页
第3页 / 共21页
c简易文本编辑器ttWord格式.docx_第4页
第4页 / 共21页
c简易文本编辑器ttWord格式.docx_第5页
第5页 / 共21页
点击查看更多>>
下载资源
资源描述

c简易文本编辑器ttWord格式.docx

《c简易文本编辑器ttWord格式.docx》由会员分享,可在线阅读,更多相关《c简易文本编辑器ttWord格式.docx(21页珍藏版)》请在冰豆网上搜索。

c简易文本编辑器ttWord格式.docx

FILE*fp;

charpd,ch;

charname[30];

inti=0;

printf("

输入A:

确定打开文件(未保存的数据将会丢失)M:

返回主菜单"

fflush(stdin);

pd=getchar();

if(pd=='

A'

||pd=='

a'

{

printf("

请输入要打开文件名字(例如c:

\\a.txt)"

scanf("

%s"

name);

while((fp=fopen(name,"

r"

))==NULL)

{

printf("

\n打开文件失败,请重新输入要打开的文件名:

scanf("

}

cs(text);

while(!

feof(fp))

ch=fgetc(fp);

text[i]=ch;

i;

text[i]='

\0'

ntext=i;

fclose(fp);

\n文件读取成功\n文件内容为\n"

dayin(text);

}

M'

m'

menu();

}

voidbc(chartext[])

charpd;

chartmp;

inti;

\n输入【A】保存;

任意键返回主菜单不保存\n"

if(!

(pd=='

))

menu();

else

if(name[20]==NULL)

{

\n请输入保存文件名(例如:

c:

\\a.txt):

}

w"

文件不存在,请重新输入文件名:

}

\nA:

确定;

B:

取消:

while(scanf("

%c"

&

tmp)!

=EOF)

if(tmp=='

||tmp=='

{

for(i=0;

i<

ntext;

i)

fprintf(fp,"

text[i]);

fclose(fp);

status=1;

printf("

\n文件保存成功\n"

break;

}

B'

b'

}

voidcs(chartext[])

for(i=0;

i)

ntext=0;

status=0;

}

intstrindex(chartext[],chart[],inti2,intl)//查找要操作的数据的位置(模式匹配)

inti1=l,j=0;

while(i1<

ntext&

&

j<

i2)

if(text[i1]==t[j])//继续匹配下一个字符

j;

i1;

//主串和子串依次匹配下一个字符

else//主串、子串指针回溯重新开始下一次匹配

i1=i1-j1;

//主串从下一个位置开始匹配

j=0;

//子串从头开始匹配

if(j>

=i2)

return(i1-i2);

}//返回匹配的第一个字符的下标

else

return(-1);

//模式匹配不成功

voidmenu()

time_ttimep;

time(&

timep);

ctime(&

timep));

\n\n\n\n\n\n\n\n\n\t\t\tWelcomtouseourTXTeditionsystem!

\n"

\n\n\t\t\t欢迎您使用文本编辑器软件!

\n\n\n\n\n\n\n\n\npressEntertocontinue...\n"

getchar();

loop:

\n\n\n\n\t\t******************简易文本编辑器*****************\n\n"

\t\t\t\t----0.清空内容--\n"

\t\t\t\t----1.打开文件--\n"

if(ntext==0){

\t\t\t\t----2.输入内容--\n"

}

else{

\t\t\t\t----2.继续输入--\n"

\t\t\t\t----3.查找------\n"

\t\t\t\t----4.插入------\n"

\t\t\t\t----5.删除------\n"

\t\t\t\t----6.替换------\n"

\t\t\t\t----7.显示内容--\n"

\t\t\t\t----8.保存------\n"

\t\t\t\t----9.退出------\n"

\n\t\t*********************选项************************\n"

\n\t\t\t\t输入选项0-9:

charn;

n=getchar();

if(n>

='

0'

n<

9'

switch(n)

case'

:

cs(text);

break;

1'

dakai(text);

2'

shuru(text);

3'

chazhao(text,0);

4'

charu(text,1);

5'

shanchu(text,0);

6'

tihan(text,0);

7'

dayin(text);

8'

bc(text);

tuichu(status);

default:

break;

\n输入有误,请重新输入:

fflush(stdin);

n=getchar();

pause"

gotoloop;

voidchazhao(chartext[],intl)

inti,t,a=-1;

charpattern[20],bd,pd;

原文为:

请输入您要查找的内容"

scanf("

pattern);

您查找的内容是:

%s\n"

t=strlen(pattern);

a=strindex(text,pattern,t,l);

if(a!

=-1)

l=at;

inths=1,ls=0;

=a;

ls;

if(text[i]=='

\n'

hs;

ls=0;

if(a==-1)

查找到结尾没有找到\n输入R将重头查找;

任意键返回主菜单"

l=0;

pd=getchar();

已经找到在第%d行第%d列,输入R继续查找下一处;

hs,ls);

bd=getchar();

if(bd=='

R'

||bd=='

r'

{l=0;

chazhao(text,l);

voiddayin(chartext[])

现在文本的内容为:

text);

inths=1,i;

for(i=0;

if(text[i]=='

hs;

\n文本共有%d行\n"

hs);

voidshuru(chartext[])

请输入内容(输入@结束输入并返回主菜单):

charc;

inti=ntext,j=ntext;

while((c=getchar())!

@'

text[i]=c;

i;

ntext=i;

continue;

intcout=0,zf=0,h=1,hs=1,zfs=0;

for(;

cout<

cout)

zf;

if(text[cout]=='

{h;

zf--;

'

zf--;

for(cout=j;

zfs;

{hs;

zfs--;

zfs--;

统计:

文本一共有%d个字符,%d行,本次输入了%d个字符,%d行\n"

zf,h,zfs,hs);

voidshanchu(charp[],intl)

inti,a=-1,t2=0;

charx[20],px,pd,pdx,c;

p);

\n输入【A】执行查找删除内容;

任意键返回主菜单:

px=getchar();

if(px=='

||px=='

\n输入您要删除的内容,以@结束:

while((c=getchar())!

if(c=='

else

x[t2]=c;

t2;

continue;

a=strindex(p,x,t2,l);

inths=1,ls=0;

ls;

if(p[i]=='

ls=0;

if(a==-1)

已查找结束,您要删除的内容不存在\n输入【R】重新输入要删除的内容;

其他键将返回主菜单:

l=0;

fflush(stdin);

pdx=getchar();

else

你要删除的内容在第%d行第%d列\n输入【A】确定删除;

输入【B】寻找下个词;

pd=getchar();

l=t2a;

if(pd=='

for(i=a;

p[i]=p[it2];

ntext=ntext-t2;

printf("

删除成功,删除后的内容为:

\n%s\n"

elseif(pd=='

gotoloop;

if(pdx=='

||pdx=='

shanchu(text,l);

voidcharu(chartext[],intl)//向文本中插入内容

inti=0,t=0,t2=0,a=-1,b;

charcr[20]="

pd,x[500],c,d;

\n当前文本信息为:

\n输入您要在哪个内容前插入,以@结束:

)//用一个数组接收要插入在哪个内容之前

if(c=='

break;

else

cr[t]=c;

t;

a=strindex(text,cr,t,l);

//查找并返回要插入的位置点

for(b=0;

b<

a;

b)

if(text[b]=='

ls=0;

\n查找到结尾没有找到插入点,输入【R】查找其他;

按其他键返回菜单:

d=getchar();

\n您要插入的位置是第%d行,第%d列之前\n【A】.不是此位置向后继续找插入点\n【B】.在此位置插入\n按其他键返回菜单\n请选择:

hs,ls1);

if(pd=='

elseif(pd=='

\n\n输入您要插入的内容,以@结束:

while((c=getchar())!

for(i=ntext;

i>

i--)

text[it2]=text[i];

for(i=0;

t2;

text[ia]=x[i];

ntext=ntextt2;

=ntext-1;

\n文本插入成功\n"

getchar();

if(d=='

||d=='

charu(text,l);

voidtihan(charp[],intl)//内容替换

intt=0,t1=0,i,a,b;

charc,th[20],d,d1,bth[20];

inti2;

for(i2=0;

i2<

i2)

p[i2]);

\n输入要被替换的内容,以@结束:

)//t指替换前内容的长度

bth[t]=c;

a=strindex(p,bth,t,l);

//查找要被替换的内容的位置

if(p[b]=='

\n查找到结尾没有找到要被替换的内容\n输入【R】查找其他内容,按其他键返回主菜单键\n"

\n\n已经找到要查找的数据在第%d行第%d列\n输入【A】继续向后查找相同内容\n输入其他键将进行替换操作\n请选择:

l=ta;

charpd;

if(pd!

pd!

\n是否要替换该内容?

替换给内容;

其他键返回主菜单\n请选择:

d1=getchar();

if(d1=='

||d1=='

\n输入要替换的内容,以@结束:

)//t1指替换后的内容长度

th[t1]=c;

t1;

if(t==t1)//将要被替换的内容和替换后的内容进行长度比较

for(i=0;

t1;

p[ia]=th[i];

else

if(t>

t1)

for(i=0;

{

p[ia]=th[i];

}

for(i=at1;

p[i]=p[it-t1];

ntext=ntextt1-t;

for(i=ntext;

p[it1-t]=p[i];

替换成功"

for(i2=0;

status=0;

}

if(d=='

tihan(text,l

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

当前位置:首页 > 幼儿教育 > 少儿英语

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

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