[comp.lang.c] building a list on the fly

dsg@mitre-bedford.arpa (Dave Goldberg) (07/09/87)

I am trying to build a list from data read in from a file.  This list will
eventually be used as an argument to the Maryland Menus MUcreate function.
When I give the list some huge allocation as a default ie:

    char list[HUGENUM][HUGENUM]; 

The MUcreate function crashes on a strlen call.  My list has a maximum strlen
of 42 chars, and I have used longer menu entries in constant strings before,
so that is not the problem.

When I try to dynamically allocate the list, I don't get a crash, but along
with the desired list in the menu, I also get some blank entries and/or some
garbage depending (it seems) on the length of the list.  Most likely, my
problem is my inexperience with dynamic allocation in C.  I would like to
allocate only the number of entries, and leave the entries at a constant
width.  I think that Menus will accept that.

Please mail me any responses, as this seems to be a somewhat of a novice
request, and I don't want to clutter the net.

Thanks in advance,

Dave
--------------------------------------------------------------------------
Dave Goldberg	             ARPA: dsg@mitre-bedford.arpa
The Mitre Corporation        UUCP: linus!dsg (gets forwarded to the above)
MS B015
Bedford, MA 01730
617-271-2460