Hi everybody,
I'm trying to do an assignment and I can't figure out what this instruction meant.
"Use a dynamic array of "lines". By a "line", we mean a dynamically-allocated array of characters just large enough to hold the line we have read. Although each line must be dynamically-allocated(& of just the right size), you may assume that each line has fewer than BUFSIZE characters, where BUFSIZE is a macro with a value of 512."
So at this point, I understand that I will need to use fgets to get the line and store it dynamically using malloc() into an array. Then, it says...
"The dynamic array of "lines" needs to grow as more lines are read. ...we'll start (not counting 0) with a size of 1 & double the size everytime the array needs to grow. Example: 1 "line" to 2 "lines" then 4, 8, 16 & so on until all lines in the input are read."
I wasn't sure what was meant by that. I thought with malloc, you have to specifically declare the size right away like malloc(BUFSIZE)?
If anyone could shed some light on this, that would be great.
Any help is appreciated.
Tags: