Ben Pfaff <bl*@cs.stanford.edu> wrote in message news:<87************@pfaff.Stanford.EDU>...
re*****@yahoo.com (Chris Ritchey) writes:
I'm writting this program in c++, however I'm using char* instead of
the string class, I am ordered by my instructor and she does have her
reasons so I have to use char*. So there is alot of c in the code as
well
Well, so far you've managed to keep away from C++-specific
issues. As long as you can do that, it's fine to talk about it
in comp.lang.c. But if the discussion strays into C++ land,
please drop comp.lang.c.
I love it when I get two posts one right after the other both telling
me not to in that news group... Where else should I post? Actually
this is more for Mark whom told me not to post in comp.lang.c than it
is for Ben since he actually seams to want to help, thank you Ben!
more info below
Anyways, I have a linked list of linked lists of a class we defined, I
need to make all this into a char*, I know that I need to allocate
them into one continuous chunk of data, ie remove all the pointers.
The way that I'm currently doing this is by manually placing the data
into the cahr* at appropriate placed using sizeof on the objects I'm
placing into the the char*.
It's difficult to really give any concrete suggestions, because
you haven't explained what you're trying to do. You have a
linked list of linked lists and you want to get a char * out of
it is all we really know. You haven't mentioned what kind of
data the linked lists contain or what format you want the output
to be in. You've implied that the output is a string, but that's
all we know.
I was trying not to be confusing in my original post but I guess I
amde it too general, heres more specifics.
The Data Structure I'm converting into a char* is called
CommunicationGroup it contains 2 integers and a linked list. The
linked list inside of CommunicationGroup is a linekd list of
ObjectGroups which contains 3, well 1 int and two enums, integers and
a linked lists of Objects. Objects consist of 3 integers. I put a
"diagram" at the bottom of the post.
As for the format of the string I do need to clarify, my bad. I'm
actually not using the char* for output to the screen, it's used to
send through a socket. The program we are writting is a network
protocol so we need a way to put these data types into a char*. The
same class will accept a char* to its constructor to fill in it's data
membes.
I hope thats enoughn formation, and qht aI was wondering about was,
would it be better to insert a delimeter between the values in the
char*(or char[], not sure how I should phrase that) or to leave them
out and just access through pointer arithmatic only. for exaple how I
have it now the layout of the string would look like this:
<int><int><ObjectGroup><ObjectGroup>... Where <int> is an integer in
the char. be better to use some character, say | to seperate them,
thus the char* would become :
<int>|<int>|<ObjectGroup>|<ObjectGroup>|...
So, which way would be better? Performance is an issue and not so much
memory. Is there another way that would be good instead?
Diagram #1:
a * indicates a pointer to that object in the linked list
Communicationgroup:
|-int
|-int
|-int
|-*ObjectGroup:
| |-int
| |-int
| |-int
| |-*Object:
| | |-int
| | |-int
| | |-int
| |-*Object:
| | |-int
| | |-int
| | |-int
| |-...
| *ObjectGroup*:
| |-int
| |-int
| |-int
| |-*Object:
| | |-int
| | |-int
| | |-int
| |-*Object:
| | |-int
| | |-int
| | |-int
| |-...
|-...