【程序功能】
统计一个字符串中包含的字母串个数并找出其中最长的字母串。
所谓字母串是指一个连续的字母序列(不区分大小写),字母串之间用非字母字符分隔。函数count的功能是统计p指向的字符串中包含的字母串个数,找出的最长字母串存放在pmax指向的数组中,函数返回字母串的个数。
【测试数据与运行结果】
测试数据:you are teaeher234too.
屏幕输出:a=you are teacher234too.
number is 4
max string is:teacher
【含有错误的源程序】
#include
#include
#include
int count(char p[],char pmax[])
{ int j=0,k,m=0;
char temp[100];
while(*p)
{ while((!isalpha(*p)) && *p) p++;
k=0;
if(*p!=’\0’) m++;
while(isalpha(*p))
temp[k++]=*p++;
temp[k]="\0";
if(k { j=k;
pmax=temp;
}
}
return m;
}
void main()
{ char a[100]="you are teacher234too.",max[100];
int i;
i=count(a[],max[]);
if(i==0)
printf("a=%S: No letter strings!\n",a);
else
prinff("a=%s\nnumber is %d\nmax string is:%s\n",a,i,max);
}
【要求】
1.将上述程序录入到文件myf1.c中,根据题目要求及程序中语句之间的逻辑关系对程序中的错误进行修改。
2.改错时,可以修改语句中的一部分内容,调整语句次序,增加少量的变量说明或编译预处理命令,但不能增加其他语句,也不能删去整条语句。
3.改正后的源程序(文件名myf1.c)保存在T:盘根目录中供阅卷使用,否则不予评分