Advertisement
Guest User

Untitled

a guest
Dec 9th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #define N 50
  5. #define M 30
  6.  
  7. char *scan_sentences(){
  8. char *s = malloc(N*sizeof(char));
  9. int counter = 0;
  10. int size = N;
  11. char current_symbol;
  12. current_symbol = getchar();
  13. while ((current_symbol == ' ') || (current_symbol == '\t')){
  14. current_symbol = getchar();
  15. }
  16. while ((current_symbol!= '\n') && (current_symbol != '.')){
  17. if(counter>=size - 5){
  18. size+=N;
  19. s = realloc(s, size);
  20. }
  21. s[counter] = current_symbol;
  22. counter++;
  23. current_symbol = getchar();
  24.  
  25.  
  26. }
  27. s[counter++] = current_symbol;
  28. s[counter++] = '\n';
  29. s[counter] = '\0';
  30. return s;
  31. }
  32.  
  33. int main(){
  34. char **pointers = malloc(M*sizeof(char*));
  35. int counter = 0;
  36. int size = 10;
  37. char *s;
  38. int sizeofmymassive = 0;
  39. int lenofstr = 0;
  40. while(lenofstr<10){
  41. s = scan_sentences();
  42. lenofstr += strlen(s);
  43. if (counter == size - 1) {
  44. size += 10;
  45. pointers = realloc(pointers, size * sizeof(char *));
  46. }
  47. pointers[counter] = s;
  48. counter++;
  49. sizeofmymassive++;
  50. }
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement