#include
#include
#include
#include
void page_title(char *menu_item)
{
printf("\n>>> 文章编辑 }
void Statistic()
{
int pNum=0,pNumSpace=0, pNumAll=0,shuzi=0;
int i=0;
int ret;
char a[1000],filename[80];
FILE *p;
printf("请输入文件名称:\n");
fflush(stdin);
scanf("%s",filename);
p=fopen(filename,"r") ;
ret=fread(a,1,1213,p);
a[ret]='\0';
char *pcur=a;
while(*pcur!='\0')
{
if((*pcur>0x40&&* pcur0x60&&*pcur if(*pcur==0x20) pNumSpace++;
if(*pcur>='0'&&*pcur pNumAll++;
pcur++;
}
printf("英文字母数=%d,空格数=%d,数字数=%d,总字数=%d",pNum,pNumSpace,shuzi,pNumAll);
fclose(p);
}
void GetTime()
{
int i=0;
char c[1000],filename[80], p[100];
int ret,n=0;
FILE *fp;
printf("请输入文件名称:\n");
fflush(stdin);
scanf("%s",filename);
printf("请输入所查字符:\n");
while(p[n]!='\n')
{
scanf("%s",p);
n++;
}
fp=fopen(filename,"r") ;
ret=fread(c,1,1213,fp);
c[ret]='\0';
char *a=c;
char *temp=a;
char *b=p;
int num=0,isok=0;
while(*a!='\0')
{
while(*b!='\0')
{
temp=a;
b=p;
if(*(temp++)==*(b++))
isok=1;
else
isok=0;
}
if(isok)num++;
a++;
}
printf("%s",p);
printf("的个数%d",num);
}
void DelString()
{
char filename[100],p[10],c[1000];
int i,ret=0;
FILE *fp;
printf("请输入文件名称:\n");
fflush(stdin);
scanf("%s",filename);
printf("请输入删除字符:\n");
scanf("%s",p);
fp=fopen(filename,"r") ;
ret=fread(c,1,1213,fp);
c[ret]='\0';
char *a=c,*temp=a,*b=p;
int num=0,isok=0;
while(*a!='\0')
{
temp=a;
b=p;
while(*b!='\0')
{
if(*(temp++)==*(b++))
isok=1;
else
isok=0;;
}
if(isok)
{
while(*temp!='\0'&&(*(a++)=*(temp++)))
*a='\0';
}
a++;
}
for(i=0;i printf("删除后%s",c[i]);
}
void shuru()
{
printf("请输入新建文件名称:\n");
FILE *fp;
char ch,filename[80];
fflush(stdin);
scanf("%s",filename);
if ((fp=fopen(filename,"w"))==NULL)
{
printf("cannot open flie\n");
exit(0);
}
printf("input char \n");
fflush(stdin);
ch=getchar();
while(ch!='#')
{
fputc(ch,fp);
ch=getchar();
}
putchar(10);
fclose(fp);
}
void main()
{
int choice;
menu: page_title("操作选单");
printf("请用数字键输入您想要的操作\n\n");
printf(" 1 输入文件\n 2 统计\n 3统计特定字符\n 4删除\n 5查找与替换\n");
printf(" 0 退出\n\n");
scanf("%d",&choice);
switch(choice)
{
case 1: shuru();break;
case 2: Statistic() ;break;
case 3: GetTime() ;break;
case 4: DelString() ;break;
case 0: exit(0);
}
goto menu;
}