| delorie.com/archives/browse.cgi | search |
| From: | "Campbell, Rolf [SKY:1U32:EXCH]" <cp1v45 AT americasm01 DOT nt DOT com> |
| Newsgroups: | comp.os.msdos.djgpp |
| Subject: | Re: From Bytes to Int and Char |
| Date: | Fri, 13 Aug 1999 14:41:27 -0400 |
| Organization: | Nortel Networks |
| Lines: | 21 |
| Message-ID: | <37B466D7.958F09E5@americasm01.nt.com> |
| References: | <rfXs3.4$bZ1 DOT 1603 AT typhoon01 DOT swbell DOT net> |
| NNTP-Posting-Host: | bmerhc00.ca.nortel.com |
| Mime-Version: | 1.0 |
| X-Mailer: | Mozilla 4.7 [en] (X11; I; HP-UX B.10.20 9000/712) |
| X-Accept-Language: | en |
| To: | djgpp AT delorie DOT com |
| DJ-Gateway: | from newsgroup comp.os.msdos.djgpp |
| Reply-To: | djgpp AT delorie DOT com |
Nick wrote:
> I am trying to load some data from a files, the 6 and 7th bytes are an
> Integer and so are the 11th and 12th. How do I make them into an INT? This
> is what I used earlier
>
> char ver, type;
> int sz, tz;
>
> sz = file_buffer[6] + file_buffer[7];
> is that right?
No. Here's the right way to do it. This code is not edian safe.
sz = *(short*)(file_buffer+6);
--
-Rolf Campbell (39)3-6318
| webmaster | delorie software privacy |
| Copyright © 2019 by DJ Delorie | Updated Jul 2019 |