home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / c / 18643 < prev    next >
Encoding:
Text File  |  1992-12-21  |  1.5 KB  |  62 lines

  1. Path: sparky!uunet!pmafire!news.dell.com!natinst.com!cs.utexas.edu!zaphod.mps.ohio-state.edu!caen!kuhub.cc.ukans.edu!nrlvx1.nrl.navy.mil!donohue
  2. Newsgroups: comp.lang.c
  3. Subject: turboc
  4. Message-ID: <1992Dec18.140840.891@nrlvx1.nrl.navy.mil>
  5. From: donohue@nrlvx1.nrl.navy.mil
  6. Date: 18 Dec 92 14:08:40 -0400
  7. Organization: NRL SPACE SYSTEMS DIVISION
  8. Lines: 52
  9.  
  10. This is a followup to the turbo C question I had posted earlier
  11. This code works in vax C, but when it is called in turbo c it produces 
  12. a floating point error:domain.  It does allow a string to be entered, but
  13. once it is, an error occurs.  Can anybody tell me what the discrepency
  14. in turbo c is that I don't see?  Thanks
  15.  
  16. John Donohue
  17.  
  18. #include <stdio.h>
  19. #include <math.h>
  20. #include <float.h>
  21. #include <stdlib.h>
  22. #include <ctype.h>
  23. #define issign(c)  (((c) == '-' || (c) == '+') ? (1):(0))
  24. #define size 12
  25. #define YES 1
  26. #define NO 0
  27. main ()
  28. {
  29. char ch;
  30. static char number[size];
  31. int digit;
  32. float value;
  33. double atof();
  34. int count;
  35. M10: count = 0;
  36.  digit = YES;
  37. printf("ENTER NUMBER \n");
  38. gets(number);
  39.     if (number[size -1] != '\0')
  40.         {
  41.         puts("Too many digits; You wiped me out.");
  42.         number[size-1] = '\0';
  43.         goto M10;
  44.         }
  45. while ((ch = number[count]) != '\0' && digit == YES)
  46.     {
  47.     if (!issign(ch) && !isdigit(ch))
  48.         {
  49.         digit = NO;
  50.         printf("That doesn't look like an number\n");
  51.         goto M10;
  52.         }
  53.     if (digit == YES)
  54.     {
  55.     value = atof(number);
  56.     printf("The number was %f \n",value);
  57.     goto stoper;
  58.     }
  59.     }    
  60. stoper: printf("PROGRAM DONE\n");    
  61. }
  62.