For some reason anything I try results in numbers after the decimal place being disregarded.
sscanf(argv[5], "%.2lf", &add4);
doesn't work
add4 = atof(argv[5]);
doesn't work
Any help?
1: program name (aka for the program im trying to solve currently, i need the following parameters. of these, double isnt getting saved properly)
2: string
3: int
4: int
5: double
all but the double are being copied into my arrays fine. I've tried the above two ways of copying the double but both result in numbers after the decimal being .00
Declarations:
char add1[50];
int add2, add3;
double add4;
This call adds a new line to a list .csv file:
inv add banana 2 2 2.50
where below, command
has already been assigned the string "add".
what would end up listed would be:
"banana, 2, 2, 2.00" at the end of my text file
if(strcmp(command,"add") == 0)
{
strcpy(add1, argv[2]);
add2 = atoi(argv[3]);
add3 = atoi(argv[4]);
add4 = atof(argv[5]);
FILE *fp3 = fopen("replica.csv", "w");
for(j=0;j<i;j++)
{
fprintf (fp3, "%s,%d,%d,%.2lf\n", item[j], quantity[j], limit[j], cost[j]);
}
fprintf(fp3, "%s,%d,%d,%.2lf\n", add1, add2, add3, add4);
fclose(fp1);
fclose(fp3);
remove("inventory.csv");
rename("replica.csv", "inventory.csv");
}