Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <malloc.h>
  3. #include <string.h>
  4. #define INIT 200
  5. #define DRAGON "Dragon flew away!"
  6.  
  7. int mass = 0;
  8.  
  9. char* sentence(){
  10.     int size = INIT;
  11.     int n = 0;
  12.     char* buf = (char*)malloc(size * sizeof(char));
  13.     char c;
  14.     int flag = 1;
  15.     do {
  16.         c = getchar();
  17.         if(flag){
  18.             if ((c == ' ') || (c == '\t')) {
  19.             --flag;
  20.             continue;
  21.             }
  22.         }
  23.         buf[n] = c;
  24.         n++;
  25.         if(n == size - 2){
  26.             size+=INIT;
  27.             buf = (char*)realloc(buf, size * sizeof(char));
  28.         }
  29.     }while(!strchr("!?;.", c));
  30.     buf[n] = '\0';
  31.  
  32.     return buf;
  33. }
  34.  
  35. char** text(){
  36.     int size = INIT;
  37.     int n = 0;
  38.     char* tm;
  39.     int i = 0;
  40.     char** buf = (char**)malloc(size * sizeof(char*));
  41.     do
  42.     {
  43.         tm = sentence();
  44.         mass++;
  45.         if(tm[strlen(tm)-1] == '?'){
  46.             free(tm);
  47.  
  48.         }
  49.         else{
  50.             buf[n] = tm;
  51.             n++;
  52.             if(n == size-1){
  53.                 size += INIT;
  54.                 buf = (char**)realloc(buf, (size+1) * sizeof(char*));
  55.             }
  56.         }
  57.     }while(strcmp(buf[n-1], DRAGON));
  58.     return buf;
  59.  
  60. }
  61.  
  62.  
  63. int main() {
  64.     char** test;
  65.     int o;
  66.     int i = 0;
  67.     int count = 0;
  68.     int fr;
  69.     test = text();
  70.     while(strcmp((test[count]), DRAGON))
  71.         count++;
  72.     for(o = 0; o <= count; o++){
  73.         printf("%s\n", test[o]);
  74.     }
  75.     printf("Количество предложений до %d и количество предложений после %d", (mass-1), count);
  76.     for (fr = 0; fr < mass; fr++) {
  77.     free(test[fr]);
  78.     }
  79.     free(test);
  80.    return 0;
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement