Structure hopping

Mike Gallagher gallag at hpanui.HP.COM
Fri Jan 4 10:07:34 AEST 1991


> dump a structure to a file (or whatever) using pointers, if we
> I would LIKE to be able to do something like this:
> char	*struct_ptr;
> struct_ptr = mr_structure
> while (struct_ptr != "whatever it is that signals the end of a structure") {
> 	putc (*struct_ptr, fp);
> }

Try this:

char *struct_ptr, *end_ptr;

struct_ptr = (char *)&mr_structure;
               /*    ^ note the missing & above */

end_ptr = struct_ptr + sizeof(mr_structure);

while (struct_ptr != end_ptr) {
    putc (*struct_ptr++, fp);
}

Mike



More information about the Comp.lang.c mailing list