Hi I have the following code:
(The infile has lines like: C0001:1001:1(string:0s and 1s:0 or 1))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 output is:
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: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 ------
Is the (double)line2[2]-48 the best way to do what I want to do?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
-deprekate



LinkBack URL
About LinkBacks



