fork(5) download
  1. #include <stdio.h>
  2. #include<stdio.h>
  3. #include<string.h>
  4.  
  5. #define MAXWORD 32
  6. typedef struct
  7. {
  8. char word[MAXWORD];
  9. int count;
  10. } word_and_count_t;
  11.  
  12. #define MAXWORDCOUNT 1024
  13. word_and_count_t table[MAXWORDCOUNT];
  14.  
  15. int table_size;
  16.  
  17. word_and_count_t* find( const char* word ) // range checking ignored
  18. {
  19. int i;
  20.  
  21. for ( i = 0; i < table_size; ++i )
  22. if ( !strcmp( table[i].word, word ) )
  23. return table + i;
  24.  
  25. strcpy( table[i].word, word );
  26. table[i].count = 0;
  27.  
  28. ++table_size;
  29.  
  30. return table + i;
  31. }
  32.  
  33. void display()
  34. {
  35. for ( int i = 0; i < table_size; ++i )
  36. printf( "%s - %d\n", table[i].word, table[i].count );
  37. }
  38.  
  39. int main()
  40. {
  41. //
  42. char s[] = "The greatness of a man is not in how much wealth he acquires, but in his integrity and his ability to affect those around him positively.";
  43.  
  44. //
  45. for ( char* word = strtok( s, " ,." ); word; word = strtok( 0, " ,." ) )
  46. find( word )->count++;
  47.  
  48. //
  49. display();
  50.  
  51. return 0;
  52. }
Success #stdin #stdout 0s 9464KB
stdin
Standard input is empty
stdout
The - 1
greatness - 1
of - 1
a - 1
man - 1
is - 1
not - 1
in - 2
how - 1
much - 1
wealth - 1
he - 1
acquires - 1
but - 1
his - 2
integrity - 1
and - 1
ability - 1
to - 1
affect - 1
those - 1
around - 1
him - 1
positively - 1