Advertisement
zenddos

Untitled

May 20th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.45 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <cstdlib>
  3. #include <iostream>
  4. #include <string>
  5. #include <locale.h>
  6. #include <windows.h>
  7.  
  8. using namespace std;
  9.  
  10. void Get_String(char **str, int clear_str);
  11. bool Is_Empty(char **str, int clear_str);
  12. int Length_Str(char buffer[]);
  13. void Swap(char **str, int index);
  14. void Sort(char **str, int N);
  15.  
  16. void Array_Initialization(int *array, int N);
  17. int Get_Index(int N);
  18. int  Average(int *array, int N);
  19. void Zeroes_Initialization(int *array, int N, int M, int average);
  20. void Print_Array(int *array, int N);
  21. int Get_Array_Length();
  22. int Get_Array_Index(int N);
  23.  
  24. int main() {
  25.     SetConsoleCP(1251);
  26.     SetConsoleOutputCP(1251);
  27.     setlocale(LC_ALL, "Russian");
  28.     int word_num=0;
  29.     int sp_num=3;
  30.     int str_len=200;
  31.     char key;
  32.     do {
  33.         char **strings = new char*[2];
  34.         int N = 2, clear_str = 0;
  35.         do {
  36.             system("cls");
  37.             while (clear_str != N) {
  38.                 Get_String(strings, clear_str);
  39.                 if (Is_Empty(strings, clear_str)) {
  40.                     cout << "You have entered an empty line repeat\n";
  41.                 }
  42.                 else {
  43.                     clear_str++;
  44.                 }
  45.             }
  46.  
  47.  
  48.  
  49.             cout << "Press Space if you want to exit or any another key to add new string\n";
  50.  
  51.             key = getchar();
  52.             if (key != 32) {
  53.                 N++;
  54.                 strings = (char **)realloc(strings, N * sizeof(char**));
  55.             }
  56.  
  57.  
  58.  
  59.             getchar();
  60.  
  61.         } while (key != 32);
  62.  
  63.         for (int i = 0; i < (N); i++) {
  64.             str_len = strlen(strings[i]); printf(" ");
  65.             for (int j = 1; j < str_len; j++) {
  66.                 if ((strings[i][j - 1] != 32 && strings[i][j - 1] != 10) && (strings[i][j] == 32 || strings[i][j] == 10)) {
  67.                     word_num++;
  68.                 }
  69.                 cout << strings[i][j-1]; //вывод слов
  70.                 if ((word_num % sp_num == 0)&&(word_num!=0)) {
  71.                     printf("        END\n "); // проверка на деление
  72.                     word_num = 0;
  73.                 }
  74.             }
  75.         }
  76.  
  77.         for (int i = 0; i < N; i++) {
  78.             free(strings[i]);
  79.         }
  80.         free(strings);
  81.  
  82.         cout << "Press Space if you want to exit\n";
  83.         key = getchar();
  84.         getchar();
  85.     }while (key != 32);
  86.  
  87.     cout << "End\n";
  88.  
  89.     //second problem
  90.  
  91.  
  92.     system("Pause");
  93.     return 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement