Advertisement
Guest User

Untitled

a guest
Mar 1st, 2015
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. //---------------------------------------------------------------------------
  2.  
  3. #include <vcl.h>
  4. #include <stdio.h>
  5. #include <io.h>
  6.  
  7. #pragma hdrstop
  8.  
  9. #include "Unit1.h"
  10. //---------------------------------------------------------------------------
  11. #pragma package(smart_init)
  12. #pragma resource "*.dfm"
  13. TForm1 *Form1;
  14.  
  15. AnsiString File_Zap;
  16. FILE *pFile;
  17.  
  18. //---------------------------------------------------------------------------
  19. __fastcall TForm1::TForm1(TComponent* Owner)
  20. : TForm(Owner)
  21. {
  22. }
  23. //---------------------------------------------------------------------------
  24. void __fastcall TForm1::FormCreate(TObject *Sender)
  25. {
  26. Memo1->Clear();
  27. }
  28. //---------------------------------------------------------------------------
  29. void __fastcall TForm1::Button1Click(TObject *Sender)
  30. {
  31. Memo1->Clear();
  32. OpenDialog1->Title="Открыть файл";
  33. if (OpenDialog1->Execute()) {
  34. File_Zap = OpenDialog1->FileName;
  35. if ((pFile=fopen(File_Zap.c_str(),"rb, ccs=UTF-8"))==NULL) {
  36. ShowMessage("Ошибка открытия ФАЙЛА!");
  37. return;
  38. }
  39. }
  40. char i;
  41. int words = 1;
  42. int test;
  43. int count[255];
  44. for(int n=0;n<255;n++)count[n] = 0;
  45. while(1)
  46. {
  47. i = fgetc(pFile);
  48. if(i == EOF)
  49. {
  50. fclose(pFile);
  51. break;
  52. }
  53. else
  54. {
  55. //Memo1->Lines->Add(i);
  56. if(i == ' ') words ++;
  57. if((i>=65 && i<=90) || (i>=97 && i<=122) || (i>=128 && i<=175) || (i>=224 && i<=241) )
  58. count[i] ++;
  59. }
  60. }
  61. Memo1->Lines->Add("Words: "+IntToStr(words));
  62. for(int j=0;j<255;j++)
  63. {
  64. if(count[j] != 0)
  65. {
  66. char txt[32];
  67. sprintf(txt, "0 - %d",count[j]);
  68. txt[0] = j;
  69. Memo1->Lines->Add(txt);
  70. }
  71.  
  72. }
  73. }
  74. //---------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement