home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20228 < prev    next >
Encoding:
Internet Message Format  |  1993-01-27  |  2.3 KB

  1. Path: sparky!uunet!ferkel.ucsb.edu!taco!gatech!udel!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!bounce-bounce
  2. From: imes@cis.ohio-state.edu (jeffrey imes)
  3. Newsgroups: comp.lang.c
  4. Subject: Problem with BC 3.1 vs. Gnu C
  5. Date: 26 Jan 1993 10:57:19 -0500
  6. Organization: The Ohio State University Dept. of Computer and Info. Science
  7. Lines: 47
  8. Message-ID: <1k3n0vINNg09@boa.cis.ohio-state.edu>
  9. NNTP-Posting-Host: boa.cis.ohio-state.edu
  10.  
  11. I have a program (my first!) written in ANSI C that works fine when I compile
  12. and run it on our Gnu C compiler under UNIX at school.  When I bring the same
  13. program to Borland C/C++ 3.1 at home (after slight mods...not with problematic
  14. part of code...) and run it it fails to work the same.
  15.  
  16. Here's the situation:
  17. The program is very simple.  It just reads in decimal (integer) numbers from 1
  18. to max size of type (using unsigned int in UNIX, unsigned long in DOS...should
  19. produce same range) and converts them to a string of "hexadecimal" characters
  20. (I quote that since they're not actual hex, just actual ASCII characters
  21. re would look like in hex) look like in hex).  When run under UNIX, it will
  22. successfully read in any number from 1 to 2,147,483,647 and convert it to hex.
  23. When run under DOS, at every multiple of 2^16 (65536) I think overflow occurs
  24. and it resets the number back to zero.  So 1=1, 10=A, 16=10,...,65535=7FFF,
  25. and then 65536 won't work.  Then, 65537=1,65538=2,...
  26.  
  27. Here's the code:
  28.  
  29. .
  30. .
  31. .           or long for BC
  32. main()           |
  33. {           V
  34.     unsigned int    dec_num,temp,.....;
  35.     char    hex_num[10],hex,....;
  36.  
  37.     printf("input a number 1-->2^32-1: ");
  38.     scanf("%d",&dec_num);
  39.     if ((dec_num < 1) || (dec_num > 2147483647))
  40.         printf("Invalid range..try again...");
  41.     if...
  42. .
  43. .
  44. .
  45.  
  46. and on and on.  Now, shouldn't the first scanf see that 65536 is a legal
  47. number and let it go?  Then later on, why would it reset numbers greater than
  48. 65536 to 0?
  49.  
  50. If needed, I have both copies here.  Please e-mail if any ideas or solutions
  51. exist.
  52. ===============================================================================
  53. Jeffrey Imes                   "It's really tragic how a family can get torn
  54. CIS Undergraduate Student       apart by something as simple as wild dogs."
  55. imes@cis.ohio-state.edu                   -- Deep Thoughts by Jack Handey
  56. -------------------------------------------------------------------------------
  57.  
  58.