p=(ESS *)malloc(sizeof(ESS)); h=p; int i,k; FILE *fp; fp=fopen(\所输入的文本将保存在d盘的rr文本文档中 printf (\输入文章, 用Ctrl+B结束输入:\\n\按Ctrl+B(^B)将结束输入 while(1) { gets(m); //输入字符串 if(strlen(m)>1000) { printf(\超过1000字符\\n\ break; } if(m[0]==2)break; //如果发现输入 ^B,则退出输入 p=p->next=(ESS *)malloc(sizeof(ESS)); p->line=(char *)malloc(sizeof(char)*strlen(m+1)); //为结点分配空间 strcpy(p->line,m);//将字符串m,复制到p所指向的字符串中 for(i=0;i<(k=strlen(m))&&(p->line[i]!=2);i++) fwrite(&p->line[i],sizeof(char),1,fp);//写入文本文档中 fputc('\\n',fp); if(m[strlen(m)-1]==2) //除去最后一个控制符 ^B { p->line[strlen(m)-1]='\\0'; break; } }
p->next=NULL; /*最后的一个指针为空 */ h=h->next; //将下一个节点赋值到头结点中 }
int Count(ESS * h) //统计数字 {
ESS *p=h; int co=0; int i;
int Lenght; do
{
Lenght=strlen(p->line); /*计算当前 line 里的数据元素的个数*/ for(i=0;i
- 11 -
}
while((p=p->next)!=NULL); //遍历 链表不为空 return co; }
int Letter(ESS * h)//统计字母 { ESS *p=h; int co=0; int Lenght; do
{
Lenght=strlen(p->line); /*计算当前 line 里的数据元素的个数*/ for(int i=0;i
while((p=p->next)!=NULL); //遍历 链表不为空 return co; /*返回文章的字母总数*/ }
int chinese(ESS * h)//统计符号 { ESS *p=h; int co=0; int Lenght; do
{
Lenght=strlen(p->line); /*计算当前 line 里的数据元素的个数*/ for(int i=0;i
while((p=p->next)!=NULL); //遍历 链表不为空 return co; /*返回*/ }
int Space(ESS * h)//统计空格 {
ESS *p=h; int co=0;
/*计算- 12 -
int Lenght; do
{
Lenght=strlen(p->line); //计算当前 line 里的数据元素的个数 for(int i=0;i
int CountAll(ESS * h)//统计文章字数 {
ESS *p=h; //保存链表的首地址 int co=0;
do //计算总字符数 { co+=strlen(p->line); }
while((p=p->next)!=NULL); //遍历 链表 return co; }
int Find(ESS * h,char *s)//统计s出现次数 {
ESS *p=h; int co=0;
int len1=0; /*保存当前行的总字符数*/ int len2=strlen(s); /*待统计字符串的长度*/ int i,j,q; do { len1=strlen(p->line); /*当前行的字符数*/ for(i=0;i
for(j=0;j if(p->line[j+i]==s[j]) q++; if(q==len2) {co++;i=i+q-1;} } } - 13 - } while((p=p->next)!=NULL); /*遍历 链表*/ return co; } void delstring(char *s,char *str) /* *s为输入的字符串,*str为将要删除的字符*/ { char *p=strstr(s,str); /*从字符串s中寻找str第一次出现的位置*/ char m[80]; int len=strlen(s); int i=len-strlen(p);//比较两串字符串之间的字符个数 int j=i+strlen(str); int co=0; for(int k=0;k strcpy(s,m); /*返回新的字符串*/ } void DelString(ESS * h,char *str) { ESS *p=h; do { if(strstr(p->line,str)!=NULL) delstring(p->line,str);//调用删除每个字符串,只删一次。 } while((p=p->next)!=NULL); } void Out(ESS * &h)// { ESS *p=h; do { printf(\显示字符串 } while((p=p->next)!=NULL); /*遍历 链表*/ } void display() - 14 - { printf(\ printf(\ printf(\ printf(\统计数字******************\\n\ printf(\统计字母******************\\n\ printf(\统计空格******************\\n\ printf(\统计文章总字数************\\n\ printf(\统计重复字符串************\\n\ printf(\统计重复出现字符串********\\n\ printf(\删除功能******************\\n\ printf(\ printf(\ }//构造一个良好的界面良好的界面 void main() { ESS *h; create(h); display(); Out(h); printf(\ printf(\数字个数:%d \\n\ printf(\全部字母数:%d \\n\ printf(\中文字数:%d \\n\ printf(\空格个数: %d \\n\ printf(\文章总字数(含空格): %d \\n\ printf(\文章总字数(不含空格): %d \\n\ char s1[20],s2[20]; printf(\ printf(\请输入要统计的字符串:\ scanf(\ printf(\出现的次数为:%d \\n\ printf(\ - 15 - printf(\请输入要删除的某一字符串:\ scanf(\ DelString(h,s2); printf(\删除%s后的文章为:\\n\ Out(h); //调用删除函数后的显示 } - 16 -