Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #define N 50
- #define M 30
- char *scan_sentences(){
- char *s = malloc(N*sizeof(char));
- int counter = 0;
- int size = N;
- char current_symbol;
- current_symbol = getchar();
- while ((current_symbol == ' ') || (current_symbol == '\t')){
- current_symbol = getchar();
- }
- while ((current_symbol!= '\n') && (current_symbol != '.')){
- if(counter>=size - 5){
- size+=N;
- s = realloc(s, size);
- }
- s[counter] = current_symbol;
- counter++;
- current_symbol = getchar();
- }
- s[counter++] = current_symbol;
- s[counter++] = '\n';
- s[counter] = '\0';
- return s;
- }
- int main(){
- char **pointers = malloc(M*sizeof(char*));
- int counter = 0;
- int size = 10;
- char *s;
- int sizeofmymassive = 0;
- int lenofstr = 0;
- while(lenofstr<10){
- s = scan_sentences();
- lenofstr += strlen(s);
- if (counter == size - 1) {
- size += 10;
- pointers = realloc(pointers, size * sizeof(char *));
- }
- pointers[counter] = s;
- counter++;
- sizeofmymassive++;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement