Guest User

Untitled

a guest
May 20th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. int main(int argc, char* argv[])
  6. {
  7. FILE *f = fopen("filename.txt", "rb");
  8. fseek(f, 0, SEEK_END);
  9. long fsize = ftell(f);
  10. fseek(f, 0, SEEK_SET);
  11.  
  12. char *str = malloc(fsize + 1);
  13. fread(str, fsize, 1, f);
  14. fclose(f);
  15.  
  16. str[fsize] = 0;
  17. int count = 0, c = 0, i, j = 0, k, space = 0;
  18. char p[1000][512], str1[512], ptr1[1000][512];
  19. char *ptr;
  20.  
  21. for (i = 0;i<strlen(str);i++)
  22. {
  23. if ((str[i] == ' ')||(str[i] == ',')||(str[i] == '.'))
  24. {
  25. space++;
  26. }
  27. }
  28.  
  29. for (i = 0, j = 0, k = 0;j < strlen(str);j++)
  30. {
  31. if ((str[j] == ' ')||(str[j] == 44)||(str[j] == 46))
  32. {
  33. p[i][k] = '';
  34. i++;
  35. k = 0;
  36. }
  37. else
  38. p[i][k++] = str[j];
  39. }
  40.  
  41. k = 0;
  42.  
  43. for (i = 0;i <= space;i++)
  44. {
  45. for (j = 0;j <= space;j++)
  46. {
  47. if (i == j)
  48. {
  49. strcpy(ptr1[k], p[i]);
  50. k++;
  51. count++;
  52. break;
  53. }
  54. else
  55. {
  56. if (strcmp(ptr1[j], p[i]) != 0)
  57. continue;
  58. else
  59. break;
  60. }
  61. }
  62. }
  63.  
  64. for (i = 0;i < count;i++)
  65. {
  66. for (j = 0;j <= space;j++)
  67. {
  68. if (strcmp(ptr1[i], p[j]) == 0)
  69. c++;
  70. }
  71.  
  72. printf("%s %d n", ptr1[i], c);
  73. c = 0;
  74. }
  75.  
  76. return 0;
  77.  
  78. }
Add Comment
Please, Sign In to add comment