Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <malloc.h>
- #include <string.h>
- #define INIT 200
- #define DRAGON "Dragon flew away!"
- int mass = 0;
- char* sentence(){
- int size = INIT;
- int n = 0;
- char* buf = (char*)malloc(size * sizeof(char));
- char c;
- int flag = 1;
- do {
- c = getchar();
- if(flag){
- if ((c == ' ') || (c == '\t')) {
- --flag;
- continue;
- }
- }
- buf[n] = c;
- n++;
- if(n == size - 2){
- size+=INIT;
- buf = (char*)realloc(buf, size * sizeof(char));
- }
- }while(!strchr("!?;.", c));
- buf[n] = '\0';
- return buf;
- }
- char** text(){
- int size = INIT;
- int n = 0;
- char* tm;
- int i = 0;
- char** buf = (char**)malloc(size * sizeof(char*));
- do
- {
- tm = sentence();
- mass++;
- if(tm[strlen(tm)-1] == '?'){
- free(tm);
- }
- else{
- buf[n] = tm;
- n++;
- if(n == size-1){
- size += INIT;
- buf = (char**)realloc(buf, (size+1) * sizeof(char*));
- }
- }
- }while(strcmp(buf[n-1], DRAGON));
- return buf;
- }
- int main() {
- char** test;
- int o;
- int i = 0;
- int count = 0;
- int fr;
- test = text();
- while(strcmp((test[count]), DRAGON))
- count++;
- for(o = 0; o <= count; o++){
- printf("%s\n", test[o]);
- }
- printf("Количество предложений до %d и количество предложений после %d", (mass-1), count);
- for (fr = 0; fr < mass; fr++) {
- free(test[fr]);
- }
- free(test);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement