Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char *scan_sentence(){
- char *s = malloc(10*sizeof(char));
- int counter = 0;
- int size = 10;
- char current_symbol;
- current_symbol = getchar();
- while((current_symbol ='\n') && (current_symbol!=';') &&(current_symbol!='.') && (current_symbol!='?') && (current_symbol!='!')){
- if (counter==size -2){
- size+=10;
- s = realloc(s,size);
- }
- s[counter] = current_symbol;
- counter++;
- }
- s[counter++]=current_symbol;
- s[counter]='\n';
- return s;
- }
- int main(){
- char **arr = malloc(10*sizeof(char*));
- int counter = 0;
- int size = 10;
- char *s;
- do{
- s = scan_sentence();
- if(counter == size - 1){
- size+=10;
- arr = realloc(arr, size*sizeof(char*));
- }
- arr[counter]=s;
- counter++;
- }while(strcmp(s,"Dragon flew away!")==0);
- for(int i = 0; i<counter; i++){
- puts(arr[i]);
- }
- for(int i = 0; i<counter; i++){
- printf("%s", arr[i]);
- }
- for(int i = 0; i<counter; i++){
- free(arr[i]);
- }
- free(arr);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement