string - Number of Word Counts in a Sentence - C program -


i thinking of c program take sentence input , display words in number of occurances. e.g.

input = love , hate output = 2 love 1 2 , 1 hate 1 

can suggest me logic or code program? have in below program seprated words sentence.

#include<stdio.h> #include<string.h>  int main() {         char str[] = "i love , hate you";         char delims[] = " ";         int =0;         char *result = null;         result = strtok (str, delims);         while(result !=null)         {                 ++i;                 printf("%s\n",result);                 result = strtok (null, delims);         } } 

now how can store these words number of occurances in sentence.

store words in collection of kind, counter. every word see if exists in collection, , if increase counter.


Comments