EDN Admin
Well-known member
Hi,
I think the problem here is the confusion over a string and a char, I defined everything so I dont understand what the problem is>
When I enter the code "Convert_FundValueBasis" the variable "xy" passed to "xx" is "Current" but it is not being recognized in the "if" statement in the code. So there appears to be some problem it should go into the first if statement.
The value of "xx" in the function is blank "". It should be "Current" because that is what "xy" was.
Does anyone know what the probelme is here?
code...
<pre class="prettyprint declaration
int INFORCE::Convert_FundValueBasis(string xx)
{
if(xx=="Current") return 0;
if(xx=="Guarantee") return 1;
if(xx=="Secondary Guarantee") return 2;
LogFile<<"Error: Convert_SMOK_CD_ToInteger() did not read 0,S,N check SMOKER Field"<<endl; exit(0);
}
int RESERVES::Read6D_SelectorNames(vector<vector<vector<vector<vector<vector<double>>>>>> &v,vector<string> &Names,string file_loc,string file_nm)
{
string x = file_loc + file_nm;
FILE *infile;
errno_t e = fopen_s( &infile, x.c_str(), "r" );
if(infile == NULL)
{ LogFile<<"Error - unsuccessful open"<<endl; exit(0);}
else
LogFile<<"Successfully opened"<<endl;
int count = 0;
int i = 0;
char chrX[5000];
char chrX2[5000];
int xyz = 0;
int j = 0;
int p = 0;
string x1;
string xy;
int y1=0,y2=0,y3=0,y4=0,y5=0,y6=0;
fgets(chrX,sizeof(chrX)-1,infile); //Skip past header
while(fgets(chrX,sizeof(chrX)-1,infile))
{
char *ptr2 = chrX;
j=0;
p=p+1;//policy index
for(i=0;i<=strlen(chrX);i++)//Step 1: Assign chrX --> chrX2
{
if(*(ptr2 + i) == , && *(ptr2 + i+1) == ,)
{
chrX2[j]= *(ptr2+i);
j=j+1;
chrX2[j]= 0; //Assign "0" as a default if there is a blank in the file
}
else
chrX2[j] = *(ptr2+i);
j=j+1;
}
char *ptr = strtok(chrX2,",");
count = 0; //Reset Column Count
while(ptr)
{
++count;
switch(count)
{
case 1: //#N
xy = ptr;
break;
case 2: //fund_val_basis
//Current,Guaranteed,Secondary Guarantee
xy = ptr;
y2 = INFORCE::Convert_FundValueBasis(xy);
break;
case 3://gender
xy = ptr;
y3 = INFORCE::Convert_Sex_ToInteger(xy);
break;
case 4://rate_class
xy = ptr;
y4 = INFORCE::Convert_UW_CODE_ToInteger(xy);
break;
case 5://smoking_class
xy = ptr;
y5 = INFORCE::Convert_SMOK_CD_ToInteger(xy);
break;
case 6://band
xy = ptr;
y6 = INFORCE::Convert_Band_ID_ToInteger(xy);
break;
case 7: //COI Names are in the 7th Column
{ //Names[p] = string(strcpy(x1,ptr));
Names[p] = ptr;
x1 = Names[p];
if (x1.size () > 0)
{
x1.resize (x1.size () - 1);
Names[p] = x1;
//Assign COIs to table "v"
Read_COI_Values(Names[p],"",v,0,0,0,0);
}
break;
}
} //End Switch
ptr = strtok(NULL,",");
}
}//End While Loop
fclose(infile);
return 0;
} [/code]
<br/>
<br/>
<br/>
View the full article
I think the problem here is the confusion over a string and a char, I defined everything so I dont understand what the problem is>
When I enter the code "Convert_FundValueBasis" the variable "xy" passed to "xx" is "Current" but it is not being recognized in the "if" statement in the code. So there appears to be some problem it should go into the first if statement.
The value of "xx" in the function is blank "". It should be "Current" because that is what "xy" was.
Does anyone know what the probelme is here?
code...
<pre class="prettyprint declaration
int INFORCE::Convert_FundValueBasis(string xx)
{
if(xx=="Current") return 0;
if(xx=="Guarantee") return 1;
if(xx=="Secondary Guarantee") return 2;
LogFile<<"Error: Convert_SMOK_CD_ToInteger() did not read 0,S,N check SMOKER Field"<<endl; exit(0);
}
int RESERVES::Read6D_SelectorNames(vector<vector<vector<vector<vector<vector<double>>>>>> &v,vector<string> &Names,string file_loc,string file_nm)
{
string x = file_loc + file_nm;
FILE *infile;
errno_t e = fopen_s( &infile, x.c_str(), "r" );
if(infile == NULL)
{ LogFile<<"Error - unsuccessful open"<<endl; exit(0);}
else
LogFile<<"Successfully opened"<<endl;
int count = 0;
int i = 0;
char chrX[5000];
char chrX2[5000];
int xyz = 0;
int j = 0;
int p = 0;
string x1;
string xy;
int y1=0,y2=0,y3=0,y4=0,y5=0,y6=0;
fgets(chrX,sizeof(chrX)-1,infile); //Skip past header
while(fgets(chrX,sizeof(chrX)-1,infile))
{
char *ptr2 = chrX;
j=0;
p=p+1;//policy index
for(i=0;i<=strlen(chrX);i++)//Step 1: Assign chrX --> chrX2
{
if(*(ptr2 + i) == , && *(ptr2 + i+1) == ,)
{
chrX2[j]= *(ptr2+i);
j=j+1;
chrX2[j]= 0; //Assign "0" as a default if there is a blank in the file
}
else
chrX2[j] = *(ptr2+i);
j=j+1;
}
char *ptr = strtok(chrX2,",");
count = 0; //Reset Column Count
while(ptr)
{
++count;
switch(count)
{
case 1: //#N
xy = ptr;
break;
case 2: //fund_val_basis
//Current,Guaranteed,Secondary Guarantee
xy = ptr;
y2 = INFORCE::Convert_FundValueBasis(xy);
break;
case 3://gender
xy = ptr;
y3 = INFORCE::Convert_Sex_ToInteger(xy);
break;
case 4://rate_class
xy = ptr;
y4 = INFORCE::Convert_UW_CODE_ToInteger(xy);
break;
case 5://smoking_class
xy = ptr;
y5 = INFORCE::Convert_SMOK_CD_ToInteger(xy);
break;
case 6://band
xy = ptr;
y6 = INFORCE::Convert_Band_ID_ToInteger(xy);
break;
case 7: //COI Names are in the 7th Column
{ //Names[p] = string(strcpy(x1,ptr));
Names[p] = ptr;
x1 = Names[p];
if (x1.size () > 0)
{
x1.resize (x1.size () - 1);
Names[p] = x1;
//Assign COIs to table "v"
Read_COI_Values(Names[p],"",v,0,0,0,0);
}
break;
}
} //End Switch
ptr = strtok(NULL,",");
}
}//End While Loop
fclose(infile);
return 0;
} [/code]
<br/>
<br/>
<br/>
View the full article