hi
i need to fetch all words from a string that includes a paragraph.
example;
i have these arrays;
char parg[] = "hi everyone. My name is jack.";
char *words[];
and i wanna make my words[] array like this;
char *words[] = { "hi", "everyone", "My", "name", "is", "jack" };
but i coulndt find correct way. i just found a string method named strtok which claimed that it takes first word. but i just could fetch first word.
how can i fetch step by step all words, from a string to another string array? i really need it. that s a kind of word statistic analyser. i have too much things that need to be done. but i coulndt pass this problem. pls if anyone help me about this code or give me any different way to do same thing, it will make ma glad.
p.s: i am really sorry about weak english
How can i fetch word from a string?i need to fetch all words from char string.
Page 1 of 1
3 Replies - 725 Views - Last Post: 01 April 2010 - 11:58 AM
#1 Guest_erdemekinci*
How can i fetch word from a string?
Posted 01 April 2010 - 11:36 AM
Replies To: How can i fetch word from a string?
#2 Guest_Andrew Tomczak*
Re: How can i fetch word from a string?
Posted 01 April 2010 - 11:44 AM
#3
Re: How can i fetch word from a string?
Posted 01 April 2010 - 11:46 AM
You can use strtok to find other words, you just have to remember the first time, the first parameter points to the string. To find the next token, the first parameter must be NULL. Example:
Hope that helps you.
char * s = strtok("My name is Martyn"," ");
printf("%s\n", s);
while ( (s = strtok(NULL, " ")) != NULL ) {
printf("%s\n", s);
}
Hope that helps you.
#4
Re: How can i fetch word from a string?
Posted 01 April 2010 - 11:58 AM
Page 1 of 1
|
|

New Topic/Question
Reply
MultiQuote







|