TIP: Click on subject to list as thread! ANSI
echo: aust_c_here
to: Paul Wankadia
from: Michael Stapleton
date: 1996-10-26 01:54:00
subject: Re: Writing structs

-=> Quoting Paul Wankadia to All <=-

Hi Paul,

PW> Hey, everyone -- how do I write a struct to a stream?  E.g.  if
PW> I had a struct like this :

PW> Typedef struct Block1024 {
PW>      unsigned char Packet_no;
PW>      unsigned char Data[1024];
PW>      unsigned long CRC;
PW> };

PW> and then went

PW> Block1024 Packet;

PW> (to create a struct called Packet, of typedef struct Block1024),
PW> how would I then write it to a stream?
PW> Say, to the screen, to disk or to a COM port?

Try something like this:

 fwrite(&Packet, sizeof (Block1024), 1, stdout)

or even

Block1024 Packets[];

 fwrite(Packets, sizeof (Block1024), n, stdout)

where n is the number of packets to write.

Note that your Block1024 structure will require padding bytes on
some architectures.  If you have control over the data structure,
you may want to reorder like so:

 Typedef struct Block1024 {
      unsigned long CRC;
      unsigned char Data[1024];
      unsigned char Packet_no;
 };

It may still require padding (somewhere :) at the end.

Michael Stapleton of Graphic Bits.

 * AmyBW v2.10 *
... This tagline is encrypted
--- AdeptXBBS v1.07f (Registered)
* Origin: Mach One BBS (3:713/615)
SEEN-BY: 50/99 620/243 623/630 626/664 711/409 410 413 430 808 809 932 934
SEEN-BY: 712/515 713/111 317 601 611 615 618 700 826 906 914 714/906 800/1
@PATH: 713/317 711/808 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.