
-----------------------------------
Anon
Thu Feb 21, 2008 11:01 pm

Array of C-strings
-----------------------------------
I'm a little confused on how to implement this properly. (Actually this exercise showed me I'm not sure how to do dynamic 2d arrays either in C)

What I'm trying to do is declare a dynamic 2d array of char. So what tried is:
This code, either segfaults or causes windows to assume I have a trojan, depending on luck.


//counters declared at start of code

  char** start = malloc(11*sizeof(char));
  for (i=0;i2. If a more compact method exists, I'd love to hear about it!

Again, thanks for the helpful comments!

-----------------------------------
OneOffDriveByPoster
Mon Feb 25, 2008 11:59 pm

Re: Array of C-strings
-----------------------------------
Because to allocate for each block iteratively would seem like a lot of needless overhead for N>2. If a more compact method exists, I'd love to hear about it!You would need to do it that way if you have a jagged array.  Since you do not, and your sub-dimension sizes are fixed, using a struct works great.  If you do not have a jagged array but your sizes are not fixed, you could allocate a big block and refer to it through a pointer to VLA (I think).
