Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.89 KB | None | 0 0
  1. #include "pch.h"
  2.  
  3. const int MAX_WORD_LENGTH = 4;
  4. const int MAX_FILE_NAME_LENGTH = 50;
  5.  
  6. void Seminar5Init() {
  7. system("cls");
  8.  
  9. ShowSeminar5Info();
  10. ShowSeminar5Menu();
  11.  
  12. bool LoopStatus = true;
  13. int Action = -1;
  14.  
  15. while(LoopStatus == true) {
  16. Action = GetSeminar5MenuAction();
  17. if(cin.fail()) {
  18. cin.clear();
  19. cin.ignore(numeric_limits<streamsize>::max(), '\n');
  20. cout << endl << "湾觐痧尻蝽 溧眄." << endl;
  21. } else {
  22. switch (Action) {
  23. case 1:
  24. cout << "骡邃栩� 磬玮囗桢 羿殡� (爨犟桁嚯铄 觐�-忸 耔焘铍钼 � 磬玮囗梃 - " << MAX_FILE_NAME_LENGTH << "): " << endl;
  25. char FileName[MAX_FILE_NAME_LENGTH];
  26. cin >> FileName;
  27. cout << endl;
  28.  
  29. FindWords(MAX_WORD_LENGTH, FileName);
  30.  
  31.  
  32. break;
  33. case 9:
  34. LoopStatus = false;
  35. MainMenuInit();
  36. break;
  37. default:
  38. cout << endl << "象黻� 礤 磬殇屙." << endl;
  39. break;
  40. }
  41. }
  42. }
  43. }
  44.  
  45. //项桉� � 恹忸� 耠钼 � 镳邃腩驽龛�, 潆桧磬 觐蝾瘥� 礤 镳桠噱� WordLength 耔焘铍钼
  46. void FindWords(int WordLength, char* FileName) {
  47. ifstream file;
  48. int WordSize = 0;
  49. char* result = new char[0];
  50.  
  51. char Word[MAX_WORD_LENGTH]; //武眍 桤 耠钼 � 疱珞朦蜞蝈. 陪� 潆桧� 礤 漕腈磬 镳邂囹� MAX_WORD_LENGTH 耔焘铍钼.
  52. file.open(FileName);
  53. if(file.is_open()) {
  54. cout << "绣珞朦蜞�:" << endl;
  55. while (!file.eof()) {
  56. char ch;
  57. file.get(ch);
  58.  
  59. //朽玟咫屐 镳邃腩驽龛� 磬 耠钼�
  60. if ((ch == ' ') || (ch == '\'') || (ch == '.') || (ch == '!') || (ch == '?') || (ch == ',') || (ch == ';') || (ch == '"')) {
  61. if(WordSize <= MAX_WORD_LENGTH && WordSize != 0) {
  62. for(int i = 0; i < WordSize; i++) {
  63. cout << Word[i];
  64. }
  65. cout << " ";
  66. }
  67.  
  68. //铟棂噱� 爨耨桠 耦 耠钼铎
  69. for(int i = 0; i < MAX_WORD_LENGTH; i++) {
  70. Word[i] = '\n';
  71. }
  72. WordSize = 0;
  73. } else {
  74. if(WordSize < MAX_WORD_LENGTH) {
  75. Word[WordSize] = ch;
  76. }
  77. WordSize++;
  78. }
  79. }
  80. cout << endl;
  81. } else {
  82. cout << "湾忸珈铈眍 铗牮� 羿殡: " << FileName << endl;
  83. }
  84. file.close();
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement