home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!paladin.american.edu!howland.reston.ans.net!usc!sdd.hp.com!decwrl!pacbell.com!UB.com!pippen.ub.com!rfries
- From: rfries@sceng.ub.com (Robert Fries)
- Subject: Re: Problem with BC 3.1 vs. Gnu C
- Message-ID: <rfries.180@sceng.ub.com>
- Sender: news@pippen.ub.com (The Daily News)
- Nntp-Posting-Host: 128.203.1.151
- Organization: Ungermann Bass
- References: <1k3n0vINNg09@boa.cis.ohio-state.edu>
- Date: Tue, 26 Jan 1993 16:22:10 GMT
- Lines: 52
-
- In article <1k3n0vINNg09@boa.cis.ohio-state.edu> imes@cis.ohio-state.edu (jeffrey imes) writes:
-
-
- >Here's the situation:
- >The program is very simple. It just reads in decimal (integer) numbers from 1
- >to max size of type (using unsigned int in UNIX, unsigned long in DOS...should
- >produce same range) and converts them to a string of "hexadecimal" characters
- >(I quote that since they're not actual hex, just actual ASCII characters
- >re would look like in hex) look like in hex). When run under UNIX, it will
- >successfully read in any number from 1 to 2,147,483,647 and convert it to hex.
- >When run under DOS, at every multiple of 2^16 (65536) I think overflow occurs
- >and it resets the number back to zero. So 1=1, 10=A, 16=10,...,65535=7FFF,
- >and then 65536 won't work. Then, 65537=1,65538=2,...
-
- >Here's the code:
-
- >.
- >.
- >. or long for BC
- >main() |
- >{ V
- > unsigned int dec_num,temp,.....;
- > char hex_num[10],hex,....;
-
- > printf("input a number 1-->2^32-1: ");
- > scanf("%d",&dec_num);
- > if ((dec_num < 1) || (dec_num > 2147483647))
- > printf("Invalid range..try again...");
- > if...
- >.
- >.
- >.
-
- >and on and on. Now, shouldn't the first scanf see that 65536 is a legal
- >number and let it go? Then later on, why would it reset numbers greater than
- >65536 to 0?
-
- I think this is caused by using %d in your call to scanf. Using BC3.1
- this will get a 16 bit number. I'm pretty sure you need to use something like
- %ld to get a long.
-
- Robert
-
-
- //////////////////////////////////////////////////////////////////////////
- Robert Fries
- Ungermann-Bass Inc.
-
- DISCLAIMER:
- Opinions contained herein are my own, and are not necessarily those
- of Ungermann-Bass.
- //////////////////////////////////////////////////////////////////////////
-