Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int main()
  5. {
  6. char str[9*30];
  7. char *s = str;
  8.  
  9. bool eof = false;
  10.  
  11. int word_count = 0;
  12. char *words[30];
  13. int words_in[30];
  14.  
  15. while(!eof)
  16. {
  17. char *word = s;
  18. *s = getchar();
  19. while(*s != ',' && *s != '.') {
  20. s++;
  21. *s = getchar();
  22. }
  23.  
  24. if (*s == '.')
  25. eof = true;
  26.  
  27. *s = 0;
  28.  
  29. bool stored = false;
  30.  
  31. for( int i = 0; i < word_count && !stored; i++ ){
  32. if( !strcmp( words[i], word ) ) {
  33. stored = true;
  34. words_in[i]++;
  35. }
  36. }
  37.  
  38. if( !stored ) {
  39. words[word_count] = word;
  40. words_in[word_count] = 1;
  41. word_count++;
  42. }
  43.  
  44. s++;
  45. }
  46.  
  47. for( int i = 0; i < word_count; i++ ) {
  48. printf("%s %d\n", words[i], words_in[i]);
  49. }
  50.  
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement