Hi all,
I am coming accross a problem that says "C4703: potentially uninitialized local pointer variable 'data_list' used" and "C4703: potentially uninitialized local pointer variable 'filter_list' used". I have tried initilizing the pointer like I have read while googling it but have not managed to get it to work as even after trying to initialize it it still comes accross with an error.
This is my code that is giving me problems.
Thanks
void TheMenu::Load(TheFilter& Filter, TheData& Data)
{
fstream input_file;
input_file.open("task2_data.txt"); //open the file
if (!input_file)
{
cout<<"\nFile does not exist" << endl;
//exit(0);
}
else
{/////////////////////////////////////////////////////////
int data_count = -1;
int data_size = -1;
int filter_count = -1;
int filter_size = -1;
double* data_list;
double* filter_list;
while (!input_file.eof()) //while we haven't reached the end of the file
{
string str;
getline(input_file,str); //get the current line in the file (separated by \n) - get from input_file, store it in the string str
if (data_count == -1) {// 1st time entering loop get size of data array.
data_size = atoi(str.c_str());//convert string to integer
//Data.SetData(new double[data_count]);
data_list = new double[data_size];
}
if ((data_count != -1) && (data_count < data_size))
{
double val = atof(str.c_str()); // string float, double type used in other classes
data_list[data_count] = val; // data list @ position
if(data_count+1 == data_size)
{
Data.SetData(data_list);
Data.SetLength(data_size);
Data.SetValid(true);
cout << "data loaded" <<endl;
filter_count = 0; // info for next loop
data_count = data_size; // match position to number of vales, if true begin saving to class
}
}
else if (filter_count != -1)
{
if (filter_size == -1) {
filter_size = atoi(str.c_str());
filter_list = new double[filter_size];
filter_count--;
}
else if ((filter_count != -1) && (filter_count < filter_size))
{
double val = atof(str.c_str());
filter_list[filter_count] = val;
if(filter_count+1 == filter_size)
{
Filter.SetValues(filter_list);
Filter.SetLength(filter_size);
Filter.SetValid(true);
cout << "filter loaded" <<endl;
}
}
filter_count++;
}
data_count++;
}
}
}