More 2D array woes...
Dave P. Schaumann
dave at cs.arizona.edu
Mon Mar 4 10:38:14 AEST 1991
In article <1991Mar3.235114.12154 at nntp-server.caltech.edu> eychaner at suncub.bbso.caltech.edu writes:
>Here we go again, warm up the flame guns...
>
>Ok, suppose I have an array like
> char strings[NUMBER][SIZE];
>How do I add more strings to this array, i.e. make it larger, portably and
>easily. I can't realloc it, since it's not a pointer! Argh!
It's beginning to sound like what you really want is C++. In C++, you can
simulate arrays cleanly using pointers, and thus you can use realloc to
increase (or decrease) the size of your array dynamically. You could even
program it so that accessing an element beyond the end of your array
automagically made it bigger.
C is good for writing quick, reasonably simple (at least as far as data
structure manipulation goes) programs. When you find you need some
heavy-duty data structures, like dynamically sized arrays, or associative
arrays, you should seriously consider moving to C++. The learning curve
is kind of steep (even for C-literates), but ultimately a useful tool to
be able to use.
--
Dave Schaumann dave at cs.arizona.edu
'Dog Gang'! Where do they get off calling us the 'Dog Gang'? I'm beginning to
think the party's over. I'm beginning to think maybe we don't need a dog. Or
maybe we need a *new* dog. Or maybe we need a *cat*! - Amazing Stories
More information about the Comp.lang.c
mailing list