Advertisement
Guest User

Untitled

a guest
Nov 17th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. char *scan_sentence(){
  6. char *s = malloc(10*sizeof(char));
  7. int counter = 0;
  8. int size = 10;
  9. char current_symbol;
  10. current_symbol = getchar();
  11. while((current_symbol ='\n') && (current_symbol!=';') &&(current_symbol!='.') && (current_symbol!='?') && (current_symbol!='!')){
  12. if (counter==size -2){
  13. size+=10;
  14. s = realloc(s,size);
  15. }
  16. s[counter] = current_symbol;
  17. counter++;
  18. }
  19. s[counter++]=current_symbol;
  20. s[counter]='\n';
  21. return s;
  22. }
  23. int main(){
  24. char **arr = malloc(10*sizeof(char*));
  25. int counter = 0;
  26. int size = 10;
  27. char *s;
  28. do{
  29. s = scan_sentence();
  30. if(counter == size - 1){
  31. size+=10;
  32. arr = realloc(arr, size*sizeof(char*));
  33. }
  34. arr[counter]=s;
  35. counter++;
  36. }while(strcmp(s,"Dragon flew away!")==0);
  37. for(int i = 0; i<counter; i++){
  38. puts(arr[i]);
  39. }
  40. for(int i = 0; i<counter; i++){
  41. printf("%s", arr[i]);
  42. }
  43. for(int i = 0; i<counter; i++){
  44. free(arr[i]);
  45. }
  46. free(arr);
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement