String - word counting!
What I need is to show how many times the word is shown for itself and how many times like a part of a sentence. I have some idea of comparing 'word' with lenght of words in the sentence and then to use counter but i cant get it done. My brain is blocked!
while(*p2 != '\0')
if(*p1 == *p2)
printf("%d times word is shown, lenght of a word is %d", a, x);
You are trying to do something by comparing *p1 with *p2. When is the only time what these pointer's point to, would be equal?
Only when the word entered, also was the sentence entered. So that's not what you want at all.
C has some great C string functions that will help you greatly to do what you want. You need to include <string.h>, and then use a string function that looks through another string, searching for an instance of a word (or substring), you give it.
Each of these string functions has a return value to indicate if it found something or did something, etc. That returned value, will serve as your while loop controller. In pseudo code:
While (there are more instances of this word in this string)
end of while
So, hunt down the string function that does what I'm talking about, and put it to work!