I'm trying to run my program and have it convert the values in the command line to doubles.
Test Run:
./prog fname -v 1.0 2.0 3.0 4.0
But what I get is either extremely large values or the values after the decimal are truncated.
I've tried atol(),strtol() and even strolf()
Any suggestions would help.
Code:
#include <stdio.h>
int main(int argc, char** argv)
{
const char *filename;
FILE *file;
double val0,val1,val2,val3;
if(argv[2][0] == '-' && argv[2][1] == 'v' && argc == 7)
{
filename = argv[1];
file = fopen(filename, "r");
val0 = atof(argv[3],sizeof(argv[3]));
val1 = atof(argv[4],sizeof(argv[4]));
val2 = atof(argv[5],sizeof(argv[5]));
val3 = atof(argv[6],sizeof(argv[6]));
printf(">>>>>>>>>>>\n");
printf("%f %f %f %f\n",val0,val1,val2,val3);
printf(">>>>>>>>>>>\n");
}
return(0);
}