The problem is here:
if (argc != 5)
…
R=strtod(argv[5],&end);
When argc == 5
, argv[5] == NULL
. You crash when you convert a null pointer. You should be using strtod()
on argv[1]
through argv[4]
. It is unusual to use strtod()
to convert strings to integers; usually, you'd use strtol()
or one of its relatives.