Structure hopping

Mark Crafts mark at tfsg.UUCP
Thu Jan 3 08:01:05 AEST 1991


Forgive my ignorance, but is there a quick 'n' simple way to say,
dump a structure to a file (or whatever) using pointers, if we
know that the structure only consists of, (for example) chars?
I would think that you could assign a pointer to the beginning
of the structure, and (assuming structures are set up linearly)
hop down the list.  This question also brings up another one...
if this can be done, how do we know when to stop aside from
hardcoding a certain number of iterations?

For example, assume we have a structure like this:

struct grandpa_structure {
	char	data1[30];
	char	data2[23];
		.
		.
		.
	char	data95[12];
};

struct grandpa_structure mr_structure;

In other words, a structure that would be really annoying to write
out one field at a time.
I would LIKE to be able to do something like this:

(assume mr_structure to be filled in somehow)

char	*struct_ptr;
	.
	.
struct_ptr = mr_structure
while (struct_ptr != "whatever it is that signals the end of a structure") {
	putc (*struct_ptr, fp);
}

All responses are appreciated.
			Mark



More information about the Comp.lang.c mailing list