Apologies up front for not finding this already. I'd Googled earlier and didn't find what I was looking for in a reasonable amount of time. And then I've had many distractions throughout this time too.
The basic thing is this: with Code::Blocks' setup with MinGW, I tried to do this:
Code:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <errno.h>
int mygetd(double *result);
int main(void)
{
double value = -12.3;
do
{
fputs("Enter a floating-point number: ", stdout);
fflush(stdout);
} while ( !mygetd(&value) );
printf("value = %g\n", value);
return 0;
}
/**
* Attempt to read a double value from the stdin.
* @param result pointer to a double into which the result will be written if
* a double is successfully converted
* @return
* 0 - failed to convert all text into a valid double, or
* 1 - successfully obtained a double and placed its value in *result
*/
int mygetd(double *result)
{
char *end, buff [ 32 ];
fgets(buff, sizeof buff, stdin);
errno = 0;
*result = strtod(buff, &end);
if ( errno )
{
perror("strtod");
}
return !isspace(*buff) && (*end == '\n' || *end == '\0');
}
/* my output
Enter a floating-point number: 0X1P-23F
Enter a floating-point number: 0X1.fffffffffffffP1023
Enter a floating-point number: 1.7976931348623157E+308
value = 1.79769e+308
*/
It ain't takin' too kindly to some C99-okay input, and I've been trying to see if that's a bug with MinGW's standard library implementation, or if I need to further link with specific libraries.
I'll continue looking, but if anyone else cares to take the time to lend me a hand, I'll be grateful.