home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!udel!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bounce-bounce
- From: imes@cis.ohio-state.edu (jeffrey imes)
- Newsgroups: comp.lang.c
- Subject: Problem with BC 3.1 vs. Gnu C
- Date: 26 Jan 1993 10:57:19 -0500
- Organization: The Ohio State University Dept. of Computer and Info. Science
- Lines: 47
- Message-ID: <1k3n0vINNg09@boa.cis.ohio-state.edu>
- NNTP-Posting-Host: boa.cis.ohio-state.edu
-
- I have a program (my first!) written in ANSI C that works fine when I compile
- and run it on our Gnu C compiler under UNIX at school. When I bring the same
- program to Borland C/C++ 3.1 at home (after slight mods...not with problematic
- part of code...) and run it it fails to work the same.
-
- 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?
-
- If needed, I have both copies here. Please e-mail if any ideas or solutions
- exist.
- ===============================================================================
- Jeffrey Imes "It's really tragic how a family can get torn
- CIS Undergraduate Student apart by something as simple as wild dogs."
- imes@cis.ohio-state.edu -- Deep Thoughts by Jack Handey
- -------------------------------------------------------------------------------
-
-