SHARE
TWEET

Untitled

a guest Dec 9th, 2019 93 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top