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 0.98 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.  
  8. FILE *f = fopen("filename.txt", "rb");
  9. fseek(f, 0, SEEK_END);
  10. long fsize = ftell(f);
  11. fseek(f, 0, SEEK_SET);
  12.  
  13. char *str = malloc(fsize + 1);
  14. fread(str, fsize, 1, f);
  15. fclose(f);
  16.  
  17. str[fsize] = 0;
  18. int count = 0, c = 0, i, j = 0, k, space = 0;
  19. char p[1000][512], str1[512], ptr1[1000][512];
  20. char *ptr;
  21. for (i = 0;i<strlen(str);i++)
  22. {
  23. if ((str[i] == ' ')||(str[i] == ',')||(str[i] == '.'))
  24. {
  25. space++;
  26. }
  27. }
  28. for (i = 0, j = 0, k = 0;j < strlen(str);j++)
  29. {
  30. if ((str[j] == ' ')||(str[j] == 44)||(str[j] == 46))
  31. {
  32. p[i][k] = '';
  33. i++;
  34. k = 0;
  35. }
  36. else
  37. p[i][k++] = str[j];
  38. }
  39. k = 0;
  40. for (i = 0;i <= space;i++)
  41. {
  42. for (j = 0;j <= space;j++)
  43. {
  44. if (i == j)
  45. {
  46. strcpy(ptr1[k], p[i]);
  47. k++;
  48. count++;
  49. break;
  50. }
  51. else
  52. {
  53. if (strcmp(ptr1[j], p[i]) != 0)
  54. continue;
  55. else
  56. break;
  57. }
  58. }
  59. }
  60. for (i = 0;i < count;i++)
  61. {
  62. for (j = 0;j <= space;j++)
  63. {
  64. if (strcmp(ptr1[i], p[j]) == 0)
  65. c++;
  66. }
  67. printf("%s %d n", ptr1[i], c);
  68. c = 0;
  69. }
  70.  
  71. return 0;
  72.  
  73. }
Add Comment
Please, Sign In to add comment