R
ragi
I need write method which will be able to get line with variable maximum
length from file. I don't want use neither iostream nor stream from
standard library.
I was trying write this method but I have problem with segmentation
fault. I do sth wrong but I van't catch my mistake ....
Declaration could have been like that:
char* get_dynamic_line(FILE* cf, char** line, int& buf_len);
In definition:
- read from file buf_len characters
- if in *line can't find EOL or EOF realloc buffer (buf_len *= 2,
realloc and read again to greater buffer and searching EOL once again ...
- return address of 'line' or NULL
And example like that:
int begin_len = 4096;
char* line = new char[begin_len];
..
..
..
if(get_dynamic_line(file, (char**)&line, begin_len))
{
do sth with line ...
}
..
..
..
delete [] line;
Can someone show me proper way or example how to write that ?
length from file. I don't want use neither iostream nor stream from
standard library.
I was trying write this method but I have problem with segmentation
fault. I do sth wrong but I van't catch my mistake ....
Declaration could have been like that:
char* get_dynamic_line(FILE* cf, char** line, int& buf_len);
In definition:
- read from file buf_len characters
- if in *line can't find EOL or EOF realloc buffer (buf_len *= 2,
realloc and read again to greater buffer and searching EOL once again ...
- return address of 'line' or NULL
And example like that:
int begin_len = 4096;
char* line = new char[begin_len];
..
..
..
if(get_dynamic_line(file, (char**)&line, begin_len))
{
do sth with line ...
}
..
..
..
delete [] line;
Can someone show me proper way or example how to write that ?