Reading in a string from a file and need to preform basic math equations with it, therefor assuming it can't be in string form. I am attempting to use ATOF but am getting 0's and nan's in return...any suggestions?
#include <stdio.h>
#include <string.h>
#include <math.h>
int main()
{
/*Define Everything*/
FILE * fp;
FILE * fp2;
char String[50000];
char read[500000];
char out[500000];
char Diff[100];
float Decimal;
int i, j;
strcpy(read, "GREP_MARK");
strcpy(out, "Average");
fp = fopen(read,"r");
fp2 = fopen(out, "w+");
while (!feof(fp))
{
i = 0;
j = 334;
Decimal = 0;
fgets(String, 50000, fp);
while (i<=1)
{
Diff = String[j];
j++;
i++;
}
Decimal = atof(Diff);
fprintf(fp2,"The int is: %f\n", Decimal);
}
}
The string is numbers like -2.987633 and its the decimal places giving me a hard time.