6-1 改错题

测试数据来自 nnu_contest/5c3e89d7f41362131f6fbb2f

统计一个字符串(长度不超过100)中包含的字母串个数并找出其中最长的字母串。所谓字母串是指一个连续字母序列(不区分大小写),字母串之间用非字母字符分隔。
函数count的功能是统计p指向的字符串中包含的字母串个数,并将找出的最长字母串存放在pmax指向的数组中,函数返回字母串的个数。
【含有错误的源程序】
#include<stdio.h>
#include <string.h>
#include <ctype.h>
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) { j=k; pmax=temp; }
}
return m; }
int main()
{ char a[100], max[100];;
gets(a);
int i;
i=count(a[],max[]);
if(i==0)
printf("a=%s: No letter strings!\n",a);
else
printf("a=%s\nnumber is%d\nmax string is:%s\n",a,i,max);
return 0;
}

测试样例
输入:

you are teacher234too.

输出:

a=you are teacher234too.
number is 4
max string is: teacher

信息

ID
1275
难度
9
分类
(无)
标签
递交数
2
已通过
1
通过率
50%
上传者