Issues with your account? Bug us in the Discord!
(C/C++) two-dimensional dynamic array
RubberEagle
What's a rubber eagle used for, anyway?
I'm currently working on a little program, and i need to make a 2 dimensional char-array, where (at least) one dimension isn't hardcoded.
(i know how to make a one-dimensional dynamic array using malloc and calloc)
it is a file list, that is going to be submitted to another function, and the dynamic part is the number of files. I'd use a stupid simple trick like a 1d array of structs (that include a char array), but the other function only understands a 2d char array (no, reprogramming the second function is not an option (for now) [img]http://216.15.145.59/mainforums/wink.gif[/img] )
Can anyone help? Please?
Thanks
RubberEagle
(i know how to make a one-dimensional dynamic array using malloc and calloc)
it is a file list, that is going to be submitted to another function, and the dynamic part is the number of files. I'd use a stupid simple trick like a 1d array of structs (that include a char array), but the other function only understands a 2d char array (no, reprogramming the second function is not an option (for now) [img]http://216.15.145.59/mainforums/wink.gif[/img] )
Can anyone help? Please?
Thanks
RubberEagle
Comments
I'm not sure, but if I recall correctly the dynamic arrays were done using pointers pointing to the last block of the array in the memory, so you didn't have to allocate any certain amount of memory for the arrays before hand. Or was it that the pointer pointed to a place in memory where then was the information where the last block of the array is located? Like I said, it's been a long time. [img]http://216.15.145.59/mainforums/rolleyes.gif[/img] If you don't know how to use pointers check out [url="http://www.cplusplus.com/"]http://www.cplusplus.com/[/url] or some other C-language website.
Biggles IIRC knows C++ pretty well. You there Les Bigg? [img]http://216.15.145.59/mainforums/biggrin.gif[/img]
- PJH
- PJH
- PJH
thanks for the link, let's see what it does.. [img]http://216.15.145.59/mainforums/smile.gif[/img]
- PJH
If you want to go all the way, make it a class with accessor functions and stuff like that. That way, you can encapsulate all the allocation and deallocation stuff. If you want to go even further and promote code reuse, make it a templated class. [img]http://216.15.145.59/mainforums/smile.gif[/img]
------------------
[url="http://www.minbari.co.uk/log12.2263/"]Never eat anything bigger than your own head.[/url]
"Nonono...Is not [i]Great[/i] Machine. Is...[i]Not[/i]-so-Great Machine. It make good snow cone though." - Zathras