I am writing a C program on a Linux box. I am trying to convert a command line argument to a double and then check if that number is larger than MAX_K. It it is larger, I want the program to exit, but it doesn't. For example, I set MAX_K to 10^18 and then put in 1000000000000000001 as the argument and if it is larger then 1000000000000000000 then I want the program to exit, otherwise print "OK", but the program doesn't exit but prints "OK". I tried defining MAX_K as a double inside the program with the same results. I don't understand why the program is not exiting since clearly 1000000000000000001 > 1000000000000000000.
Here's my code:
#include <stdio.h>
#include <stdlib.h>
#define MAX_K 1000000000000000000
int main(int argc, char *argv[]) {
// double MAX_K = 1000000000000000000;
double K;
if (argc != 2) {
exit(1);
}
K = strtod(argv[1], NULL);
if (K > MAX_K) {
exit(1);
}
printf("OK\n");
return 0;
}