Hello everyone,
I need help with this code, which does not work properly. It prints fine at the first instant and when I convert it into a double it prints some unknown value. I am trying to get the maximum of all the values in the row. First: I cant figure out how to exclude the first value of the row, which is just a indicator of how many values are in the row (shown here in bold). Second: I cant get the conversion to a float so I can do the comparison. I thank you in advance for helping me out.
Best,
newbie
the test.grf file
"IngWater_HumRcp",3,"FLOAT",0,"mg/kg-d",
1,4,
10,2.657374814e-012,2.658182387e-012,2.658989959e-012,2.659797532e-012,2.660605104e-012,2.661412675e-012,2.662220249e-012,2.663027821e-012,2.663835392e-012,2.664642966e-012,
The code:
#include <stdio.h>
#include <iostream>
#include <string.h>
int main()
{
char sizeLineInput[40980];
char *token;
char c;
int idx=0;
char num[15];
double array[10000], ADD; // Declare an array of 10,000
int n = 0;
char * pEnd;
FILE *SourceFile = fopen ("c:\\Temp\\test.grf","r");
if (SourceFile != NULL)
{
while(fgets(sizeLineInput, 10000, SourceFile)!=NULL)
{
token = strstr(sizeLineInput ,"IngWater_HumRcp");
if (token)
{
fgets(sizeLineInput, 10000, SourceFile);
while((c=fgetc(SourceFile))!='\\')
{
if(c==',')
{
num[idx]=0;
n++;
printf("%s\n",num); // Here it prints right
array[n]= atof(num);
//array[n]= strtod (num,&pEnd);
printf("%d\n", array[n]); // Here it doesnot
system("PAUSE");
idx=0;
}
else
{
num[idx] = c;
idx++;
}
}
}
}
}
for (int i=0;i<n;i++){
if (array[i+1]>array[i]){
ADD=array[i+1];}
else
ADD=array[i];
}
return 0;
printf("%s\n",ADD);
system("PAUSE");
}