home *** CD-ROM | disk | FTP | other *** search
- 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
- Newsgroups: comp.lang.c
- Subject: turboc
- Message-ID: <1992Dec18.140840.891@nrlvx1.nrl.navy.mil>
- From: donohue@nrlvx1.nrl.navy.mil
- Date: 18 Dec 92 14:08:40 -0400
- Organization: NRL SPACE SYSTEMS DIVISION
- Lines: 52
-
- This is a followup to the turbo C question I had posted earlier
- This code works in vax C, but when it is called in turbo c it produces
- a floating point error:domain. It does allow a string to be entered, but
- once it is, an error occurs. Can anybody tell me what the discrepency
- in turbo c is that I don't see? Thanks
-
- John Donohue
-
- #include <stdio.h>
- #include <math.h>
- #include <float.h>
- #include <stdlib.h>
- #include <ctype.h>
- #define issign(c) (((c) == '-' || (c) == '+') ? (1):(0))
- #define size 12
- #define YES 1
- #define NO 0
- main ()
- {
- char ch;
- static char number[size];
- int digit;
- float value;
- double atof();
- int count;
- M10: count = 0;
- digit = YES;
- printf("ENTER NUMBER \n");
- gets(number);
- if (number[size -1] != '\0')
- {
- puts("Too many digits; You wiped me out.");
- number[size-1] = '\0';
- goto M10;
- }
- while ((ch = number[count]) != '\0' && digit == YES)
- {
- if (!issign(ch) && !isdigit(ch))
- {
- digit = NO;
- printf("That doesn't look like an number\n");
- goto M10;
- }
- if (digit == YES)
- {
- value = atof(number);
- printf("The number was %f \n",value);
- goto stoper;
- }
- }
- stoper: printf("PROGRAM DONE\n");
- }
-