Xref: news2.mv.net comp.os.msdos.djgpp:3611 From: Rikard Thunberg Newsgroups: comp.os.msdos.djgpp Subject: i/o file handling - integers Date: Mon, 06 May 1996 23:40:13 +0200 Organization: Informia Lines: 18 Message-ID: <318E71BD.904@algonet.se> NNTP-Posting-Host: bengt.algonet.se NNTP-Posting-User: a37bfb8671f5d77b3 Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp What is the appropriate way to read/write integers from/to a file with the same size as it is stored in memory, i.e. a long integer (32bit) would occupy 4 bytes in the file. I have reached a solution but it seems rather clumsy: #include void main() { FILE *fileh; unsigned long my_long=0x41424344; char *charpek; fileh = fopen("test.dat","wb"); charpek= (char *) &my_long; fprintf(fileh,"%c%c%c%c",*charpek,*(charpek+1),*(charpek+2),*(charpek+3)); fclose(fileh); } /Rikard Thunberg, thunberg AT algonet DOT se