Advertisement
Guest User

Untitled

a guest
Nov 21st, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 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 - 3){
  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.             //tm[strlen(tm)] = '\n';
  51.             //tm[strlen(tm)+1]  = '\0';
  52.             buf[n] = tm;
  53.             n++;
  54.             if(n == size-1){
  55.                 size += INIT;
  56.                 buf = (char**)realloc(buf, (size+1) * sizeof(char*));
  57.             }
  58.         }
  59.     }while(strcmp(buf[n-1], DRAGON));
  60.     return buf;
  61.  
  62. }
  63.  
  64.  
  65. int main() {
  66.     char** test;
  67.     int o;
  68.     int i = 0;
  69.     int count = 0;
  70.     int fr;
  71.     test = text();
  72.     int t;
  73.     while(strcmp((test[count]), DRAGON))
  74.         count++;
  75.     for(o = 0; o <= count; o++){
  76.         printf("%s\n", test[o]);
  77.     }
  78.     printf("Количество предложений до %d и количество предложений после %d", (mass-1), count);
  79.     for (fr = 0; fr < mass; fr++) {
  80.     free(test[fr]);
  81.     }
  82.     free(test);
  83.    return 0;
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement