search word in file: i get different output like i want

Pages: 12
You cna make some function that comapes two words letter by letter and to put a two conditions:one if the letter ar same OR if they are different only by 32(that is difference between lower case and upper case) you can try.I have posted earlier a piece of code for checking only the FIRST letter but not all.dog and Dog are same,but nut doG and dog.
 
if(strcmp(p,word)==0 || p[0]+32=word[0])

You can do something like this
1
2
3
4
5
6
7
8
9
10
if(strlen(p)==strlen(word))//now only check if the words have same number of characters 
{int i=0;

while(p[i]==word[i] || (p[i]+'z'-'Z'=word[i]))
++i;//increment i while the letters are the same or they are the same but one is uppercase and one lowercase
if(i==strlen(p))//if i passed all letters our condition is true
cout<<p<<endl;
}

}

Last edited on
Topic archived. No new replies allowed.
Pages: 12