trouble casting char to double
Hi I have the following code:
Code:
i = 1;
while (fscanf(infile, "%[^:]:%[^:]:%s\n", line1,line2,line3) != EOF) {
printf("Line was composed of %s, %s, %s\n",line1,line2,line3);
for(j = 1 ; j <= NumInput ; j++){
printf("char :i=%d,j=%d and value=%c\n",i,j,line2[j-1]);
printf("float :i=%d,j=%d and value=%f\n",i,j,line2[j-1]);
printf("int :i=%d,j=%d and value=%d\n",i,j,line2[j-1]-48);
printf("float :i=%d,j=%d and value=%f\n",i,j,(double)line2[j-1]-48);
/* printf("atof :i=%d,j=%d and value=%f\n",i,j,atof(line2[j-1])); */
printf("------\n");
exit(1);
}
i++;
}
(The infile has lines like: C0001:1001:1(string:0s and 1s:0 or 1))
The output is:
Code:
Line was composed of C003, 1100, 1
char :i=1,j=1 and value=1
float :i=1,j=1 and value=-0.523882
int :i=1,j=1 and value=1
float :i=1,j=1 and value=1.000000
------
I want to be able to cast the line2[j] to a float, since it appears to be a char. But if I uncomment the atof line i get the following error:
Code:
cc pnn.c -O -lm -o pnn
pnn.c: In function ‘main’:
pnn.c:74: warning: passing argument 1 of ‘atof’ makes pointer from integer without a cast
Is the (double)line2[2]-48 the best way to do what I want to do?
-deprekate