高手帮忙修改上程序,现在就差字符串插入和替换了,明天要下交了····
高手帮忙修改下程序,现在就差字符串插入和替换了,急!急!明天要上交了····
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#define N 20 /* 文章的行数 */
char wz[N][80]; /* 存储文章的字符数组 ,为全局变量*/
/*输入函数*/
void readdat()
{FILE *fp;
int i;
if(!(fp=fopen("shiyan.txt","r+")))/*打开文件*/
printf("The file can't found!\n");
for(i=0;i<N;i++)
fgets(wz[i],80,fp);/*读文件*/
fclose(fp);
}
/*输出函数*/
void out()
{int i=0;
for(i=0;i<N;i++)
printf("%s",wz[i]);
}
/*统计ASC 码在n1与n2之间的字符*/
int countword(int n1,int n2)
{int i,j,len;
int n=0; /*统计字符数*/
for(i=0;i<N;i++)
{len=strlen(wz[i]);
for(j=0;j<=len;j++)
if(wz[i][j]>=n1&&wz[i][j]<=n2)/*wz[i][j]的ASC 码在n1与n2之间,n++*/
n++;
}
return n;
}
/*统计字符*/
void tongji()
{
int word,space,num,fuhao,zifu;/*字母数,空格数,数字数,符号数,字符数*/
/*统计小写字母*/
word=countword('a','z');
printf("\n文章中小写字母个数:\t%d\n",word);
/*统计大写字母*/
word=countword('A','Z');
printf("文章中大写字母个数:\t%d\n",word);
/*统计空格*/
space=countword(' ',' ');
printf("文章中空格个数:\t%d\n",space);
/*统计数字*/
num=countword('0','9');
printf("文章中数字个数:\t%d\n",num);
/*统符号字*/
fuhao=countword(33,47)+countword(58,64)+countword(91,96)+countword(123,126);
printf("文章中符号个数:\t%d\n",fuhao);
/*统计所有字符*/
zifu=countword(32,126);
printf("文章中总共字符个数:\t%d\n",zifu);
}
/*字符的插入和删除*/
void zfcr(char *s)
{
int n,k;
printf("输入你要插入的行数和列数:\t");
scanf("%d%d",&n,&k);
// insert(wz[n],s,k);
}
/*查找某一字符串出现的次数*/
int cz(char *s,char *t)
{int n=0;
int i;
int lens;/*要查找字符串 *S 的长度*/
char *c;
lens=strlen(s);
for(i=0;i<N;i++)
{ c=strstr(wz[i],s);/*字符串*S在文章第i 行第一次出现的位置*/
while(c!=NULL)
{n++;
s=t;
c=strstr(c+lens,s);/*字符串*S在文章第i 行下一次出现的位置*/
}
}
return n;
}
/*删除字符*/
void del(char *s)
{int i,j,k,leni,lenc,lens;
int p;
char *c;
lens=strlen(s);/*要删除字符串的长度*/
for(i=0;i<N;i++)
{ c=strstr(wz[i],s);/*字符串s 在文章第i行首次出现的位置*/
while(c!=0)/*c=0 则表明字符串s 在文章第i行没有出现*/
{leni=strlen(wz[i]);/*文章第i 行的长度*/
lenc=strlen(c);/*从字符串s 在文章第i行首次出现的位置处后的字符串的长度*/
p=leni-lenc;/* 两个长度的差 从此行的第p 个位置开始删除*/
for(k=1;k<=lens;k++)/*删除lens次*/
{
for(j=p;j<=leni;j++)
wz[i][j]=wz[i][j+1];/*字符前移*/
leni=strlen(wz[i]);
wz[i][j-1]='\0';
leni=strlen(wz[i]);
}
c=strstr(wz[i],s);
}
}
}
/*主函数*/
void main()
{
int n; /*某字符串数*/
int leni;
int i=0,j=0;
char s1[80],*s,*t;
s=(char *)malloc(80);
printf("从文件读入数据,还是从键盘输入数据?\n");
printf("从文件读入数据输入1,还是从键盘输入数据输入2\n");
scanf("%d",&n);
switch(n)
{case 1:
readdat();
break;
case 2:
printf("please input the file untill @@\n");
gets(s1);
while(strcmp(s1,"@@")!=0&&i<N)
{
strcpy(wz[i],s1);/*将s1中的内容复制到wz[i]中*/
leni=strlen(s1);
wz[i][leni]='\n';
gets(s1);
i++;
}
break;
default:
printf("Wrong input !\n");
break;
}
printf("文章中内容:\n");
#include<stdio.h>
#include<string.h>
#include<malloc.h>
#define N 20 /* 文章的行数 */
char wz[N][80]; /* 存储文章的字符数组 ,为全局变量*/
/*输入函数*/
void readdat()
{FILE *fp;
int i;
if(!(fp=fopen("shiyan.txt","r+")))/*打开文件*/
printf("The file can't found!\n");
for(i=0;i<N;i++)
fgets(wz[i],80,fp);/*读文件*/
fclose(fp);
}
/*输出函数*/
void out()
{int i=0;
for(i=0;i<N;i++)
printf("%s",wz[i]);
}
/*统计ASC 码在n1与n2之间的字符*/
int countword(int n1,int n2)
{int i,j,len;
int n=0; /*统计字符数*/
for(i=0;i<N;i++)
{len=strlen(wz[i]);
for(j=0;j<=len;j++)
if(wz[i][j]>=n1&&wz[i][j]<=n2)/*wz[i][j]的ASC 码在n1与n2之间,n++*/
n++;
}
return n;
}
/*统计字符*/
void tongji()
{
int word,space,num,fuhao,zifu;/*字母数,空格数,数字数,符号数,字符数*/
/*统计小写字母*/
word=countword('a','z');
printf("\n文章中小写字母个数:\t%d\n",word);
/*统计大写字母*/
word=countword('A','Z');
printf("文章中大写字母个数:\t%d\n",word);
/*统计空格*/
space=countword(' ',' ');
printf("文章中空格个数:\t%d\n",space);
/*统计数字*/
num=countword('0','9');
printf("文章中数字个数:\t%d\n",num);
/*统符号字*/
fuhao=countword(33,47)+countword(58,64)+countword(91,96)+countword(123,126);
printf("文章中符号个数:\t%d\n",fuhao);
/*统计所有字符*/
zifu=countword(32,126);
printf("文章中总共字符个数:\t%d\n",zifu);
}
/*字符的插入和删除*/
void zfcr(char *s)
{
int n,k;
printf("输入你要插入的行数和列数:\t");
scanf("%d%d",&n,&k);
// insert(wz[n],s,k);
}
/*查找某一字符串出现的次数*/
int cz(char *s,char *t)
{int n=0;
int i;
int lens;/*要查找字符串 *S 的长度*/
char *c;
lens=strlen(s);
for(i=0;i<N;i++)
{ c=strstr(wz[i],s);/*字符串*S在文章第i 行第一次出现的位置*/
while(c!=NULL)
{n++;
s=t;
c=strstr(c+lens,s);/*字符串*S在文章第i 行下一次出现的位置*/
}
}
return n;
}
/*删除字符*/
void del(char *s)
{int i,j,k,leni,lenc,lens;
int p;
char *c;
lens=strlen(s);/*要删除字符串的长度*/
for(i=0;i<N;i++)
{ c=strstr(wz[i],s);/*字符串s 在文章第i行首次出现的位置*/
while(c!=0)/*c=0 则表明字符串s 在文章第i行没有出现*/
{leni=strlen(wz[i]);/*文章第i 行的长度*/
lenc=strlen(c);/*从字符串s 在文章第i行首次出现的位置处后的字符串的长度*/
p=leni-lenc;/* 两个长度的差 从此行的第p 个位置开始删除*/
for(k=1;k<=lens;k++)/*删除lens次*/
{
for(j=p;j<=leni;j++)
wz[i][j]=wz[i][j+1];/*字符前移*/
leni=strlen(wz[i]);
wz[i][j-1]='\0';
leni=strlen(wz[i]);
}
c=strstr(wz[i],s);
}
}
}
/*主函数*/
void main()
{
int n; /*某字符串数*/
int leni;
int i=0,j=0;
char s1[80],*s,*t;
s=(char *)malloc(80);
printf("从文件读入数据,还是从键盘输入数据?\n");
printf("从文件读入数据输入1,还是从键盘输入数据输入2\n");
scanf("%d",&n);
switch(n)
{case 1:
readdat();
break;
case 2:
printf("please input the file untill @@\n");
gets(s1);
while(strcmp(s1,"@@")!=0&&i<N)
{
strcpy(wz[i],s1);/*将s1中的内容复制到wz[i]中*/
leni=strlen(s1);
wz[i][leni]='\n';
gets(s1);
i++;
}
break;
default:
printf("Wrong input !\n");
break;
}
printf("文章中内容:\n");