Parsing a string into a double I'm trying to understand the strtod() function, and how I can handle any user input given to the function. I assume I tested for everything, however I am hoping for a review to make sure and to catch anything I missed. (I know I should separate everything into functions, however, I am just trying to understand the nature of the function, therefore I left everything in main.)

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;string.h&gt;
#include &lt;float.h&gt;
#include &lt;stdbool.h&gt;

/*@param MAXSIZE max number of chars that are converted to a 64bit double*/
#define MAXSIZE 1077 

int main() {

    char str[MAXSIZE];
    printf("Enter a rational number: ");

    for (;;) {
        if (fgets(str, sizeof str, stdin) != NULL) {
            if (strchr(str, '\n')) {
                str[strcspn(str, "\n")] = '\0';
            }
            if (str[0] != '\0') {
                break;
            }
            printf("\nTry again: ");
        }
    }

    char* endptr = NULL;
    errno = 0;
    double number = strtod(str, &amp;endptr);

    //passes over trailing whitespace
    for (; isspace(*endptr); ++endptr);

    if (errno == ERANGE) {
        fprintf(stderr, "Error out of range...\n");
    }
    else if (*endptr != '\0') {
        fprintf(stderr, "error could not convert: %s\n", str);
    }
    else {
        printf("Your string was converted into the rational number: %lf\n", number);
    }
    printf("Your string was: %s\n", str);
    printf("Press any key to continue...\n");
    getch();
}
str[strcspn(str, "\n")] = '\0'; is an overkill. fgets reads (at most) one string, that is there is at most one '\n' in the buffer, and strchr will return its position. Consider

    char * newline = strchr(str, '\n');
    if (!newline) {
        .... // handle input too long condition
    } else if (newline == str) {
        .... // handle empty input condition
    } 
    *newline = '\0';
    break;


Notice that even newline = '\0' is redundant: '\n' is a whitespace.



Do not invent error messages. This is what strerror and perror are for. Also keep in mind that strtod may set errno to errors other than ERANGE (some implementations use EINVAL as well). Consider

    if (errno != 0) {
        perror("strtod");
    }