我们有一个函数最长,它返回由字母组成的最长子字符串.例:
longest("112****hel 5454lllllo454")
Run Code Online (Sandbox Code Playgroud)
会回来:lllllo
但是,当我运行程序时,它似乎返回lllllo454.这是功能:
char *longest(char *s){
char *pMax = NULL;
int nMax = 0;
char *p = NULL;
int n = 0;
int inside = 0; //flag
while(*s!='\0'){
char c = *s;
if((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')){
if(inside == 0){
n = 1;
p = s;
inside = 1;
}
else
n++;
if(inside == 1){
if(n > nMax){
nMax = n;
pMax = …Run Code Online (Sandbox Code Playgroud)