this is my book this is not my book .
this -------------2times
is -------------2times
my ---------------2times
book ----------2 times
not ------------ 1 times
Write a programe to count the paticular word how may times comes in the string in c language?
Assume that every word is separated by space so check for it
now put this word in a separate array, now copy this array into a new array and read this array and compare using strcmp().
Reply:u need to break sentences into word then compare them
ie. a string into multiple strings and compare
Reply:yep. u can use strtok() to tokenize ur string with %26lt;space%26gt; as delimiter;
get the tokens in an array of strings;
for each non null word in the array
{
--each word with the rest of the words;
--{
----if u find a match
----{
-----change that match to null;
-----increment the counter;
----}
--}
--make the word u have been searching for as null.
--print the count;
}
Reply:You could step through the string as a character array and consider yourself at a new word each time you reach a space. You could also look into strtok().
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment