Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "mylib4Hw5.h"
- char* getline(unsigned int first_size)
- {
- char* line = new char[first_size];
- unsigned int size_of_allocated_memory = first_size;
- char temp_char;
- unsigned int position; //the position in the line in which we will write
- for(position = 0; std :: cin.get(temp_char) && temp_char != '\n'; ++position)
- {
- if(position + 1 == size_of_allocated_memory)//at this string we resize namely when size_of_allocated_memory == position + 1, because
- { //at the end of cycle we should have one free place for zero character
- line = resize(line, size_of_allocated_memory, size_of_allocated_memory *= 2);
- }
- line[position] = temp_char;
- }
- line[position] = '0';
- return resize(line, position + 1, position + 1);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement