help me to find the bug ..
the code must print the same word that appears in the ..First sentences & Second sentences.. and must have the Max Length.
char First[]="Ann,Bob and Bill Abraham live in Alabama."
char Second[]="Alabama is where alabama Anne Abrahamson lives."
the output= Alabama
Code:#include<stdio.h> #include<ctype.h> #include<string.h> int WordLength(char *); int WordCompare(char *,char *); char *GoNextWord(char *); char *max_equivalent_words(char *pFirst , char *pSecond){ char *pTemp1=pFirst,*pTemp2=pSecond,*MaxP;int Len=0,MaxLen=0; while(*pTemp1 && isalpha(*pTemp1)==0) while(*pTemp2 && isalpha(*pTemp2)==0){ if(WordCompare(pTemp1,pTemp2)){ Len=WordLength(pTemp1); if(Len>MaxLen){ MaxP=pTemp1; MaxLen=Len; } pTemp2=GoNextWord(pTemp2); } pTemp2=pSecond; pTemp1=GoNextWord(pTemp1); } return(MaxP); } char *GoNextWord(char *pFirst){ char *p1; p1=pFirst; while(isalpha(*p1) && *p1!='\0') p1++; return (++p1); } void PrintWord(char *pWord){ char *p1=pWord; while(*p1 && isalpha(*p1)){ printf("%c",*p1); p1++; } } int WordCompare(char *pFirst,char *pSecond){ char *p1=pFirst,*p2=pSecond;int sum=0; if(WordLength(p1)!=WordLength(p2)) return 0; while(isalpha(*p1)){ if(*p1==*p2); sum=sum; p1++; p2++; } if(sum==WordLength(p1)) return 1; } int WordLength(char *Word){ char *p1;int i=0; p1=Word; while(isalpha(*p1)){ p1++; i=i+1; } return(i); } int main() { char *p1,*p2; char First[]="Ann,Bob and Bill Abraham live in Alabama."; char Second[]="Alabama is where alabama Anne Abrahamson lives."; p1=max_equivalent_words(First,Second); PrintWord(p1); return 0; }



LinkBack URL
About LinkBacks



while doing the question....hard in the battle..