Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.65 KB | None | 0 0
  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<string.h>
  4.  
  5. int main(){
  6.     int len_text = 1;
  7.     int len_sen = 1;
  8.     int i=0; // количество предложений
  9.     int j=0; //количество символов в предложении
  10.     char c;
  11.     char** text = calloc(len_text, sizeof(char*));
  12.     text[i] = (char*) calloc(len_sen, sizeof(char));
  13.     do{
  14.         c = getchar();
  15.         if(c == '.' || c == '?' || c == ';'){
  16.             text = realloc(text, sizeof(char*)*(len_text++));
  17.             text[i][j] = c;
  18.             text[i+1] = (char*) calloc(1, sizeof(char));
  19.             i++;
  20.             j=0;
  21.             len_sen = 1;
  22.             continue;
  23.         } else {
  24.             text[i][j] = c;
  25.         }
  26.  
  27.         if(j >= len_sen){
  28.             text[i] = realloc(text[i], (len_sen+=1)*sizeof(char));
  29.         }
  30.         j++;
  31.     }while(c != '!');
  32.  
  33.     int n = 0;
  34.     char f = text[0][0]; //получаем первый символ первого предложения
  35.     for(int m = 0; m <= i; m++){
  36.  
  37.         while(f != '.' || f != ';' || f != '?'){
  38.             if( text[m][n] == ' ' && text[m][n+1] == ' '){
  39.                 n++;
  40.                 continue;
  41.             }
  42.             if(text[m][n] == '\t'){
  43.                 n++;
  44.                 continue;
  45.             }
  46.             if(text[m][n] == ' ' && text[m][n+1] != ' '){
  47.                 n++;
  48.                 continue;
  49.             }
  50.             printf("%c", text[m][n]);
  51.             n++;
  52.             if(text[m][n] == text[i][j]){
  53.                 break;
  54.             }
  55.             f = text[m][n];
  56.         }
  57.         n = 0;
  58.         printf("\n");
  59.     }
  60.     return 0;
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement