int main(void) { intmax= 1;//保存最长目标字串的字符个数 int leng,count= 1;//字符串的具体长度 int i = 0; int j = 1; char str[MaxLen];
printf("-------------------------------------\n"); printf("|please input the string, thank you!|\n"); printf("-------------------------------------\n");
fgets(str, MaxLen,stdin);
while(str[i]!='\0') { while(!is_same(str, i, j)&& str[j]!='\0') { count++;
j++; } if(count>max) max=count- 1; if(str[j]=='\0') break; else { count= 1;
i = is_same(str, i ,j);
j = i + 1; } } printf("max = %d\n",max);
return 0; }
int is_same(char*str,int begin,int current) { int flag = 0;//当前字符和以前的 int i; for(i = begin; i < current; i++) if(str[i]!= str[current]) ; else {
flag = i + 1; return flag; } return flag; }