Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include "mylib4Hw5.h"
  3.  
  4. char* getline(unsigned int first_size)
  5. {
  6. char* line = new char[first_size];
  7. unsigned int size_of_allocated_memory = first_size;
  8. char temp_char;
  9. unsigned int position; //the position in the line in which we will write
  10. for(position = 0; std :: cin.get(temp_char) && temp_char != '\n'; ++position)
  11. {
  12. if(position + 1 == size_of_allocated_memory)//at this string we resize namely when size_of_allocated_memory == position + 1, because
  13. { //at the end of cycle we should have one free place for zero character
  14. line = resize(line, size_of_allocated_memory, size_of_allocated_memory *= 2);
  15. }
  16. line[position] = temp_char;
  17. }
  18. line[position] = '0';
  19. return resize(line, position + 1, position + 1);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement