We have a function longest, which returns the longest substring that consists of letters. Example:
longest("112****hel 5454lllllo454")
would return: lllllo
However, when I run the program it seems to return lllllo454. Here is the function:
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 = p;
inside = 0;
}
}
}//end isLetter if
s++;
}
return pMax;
}
There's something I'm not seeing here...what do you guys think?