Hi
i want to extract all the words in a string, so that i can compare each word with another to find the most repeated word in the whole string.
Anyone,, please help me
Hi
i want to extract all the words in a string, so that i can compare each word with another to find the most repeated word in the whole string.
Anyone,, please help me
Look into strtok() in string.h
Any example program??
Check out this snippet from the faq.
There are a few functions (including strtok) you can use to split a string on spaces (ie, separate a sentance into words), or you can write your own. Have a look at this thread, which is a discussion of exactly that.
In terms of finding duplicates: the straightforward, "brute-force" method will be fine unless you got your sentence out of James Joyce or David Foster Wallace: After you have split the string into an array, for each element in the array loop through the array using strcmp(). Use a same length, separate array of integers (ie, one for each word), all set to zero. When a duplicate is found, set the corresponding int to -1. When proceeding through the loop, skip elements that have a corresponding value of -1 (and, obviously, set the corresponding int to the number of finds at the end of the loop).
Last edited by MK27; 04-15-2009 at 09:15 AM.
C programming resources:
GNU C Function and Macro Index -- glibc reference manual
The C Book -- nice online learner guide
Current ISO draft standard
CCAN -- new CPAN like open source library repository
3 (different) GNU debugger tutorials: #1 -- #2 -- #3
cpwiki -- our wiki on sourceforge