I'm getting this exception while trying to read from text file in c++.
Windows has triggered a breakpoint in myprogram.exe.
This may be due to a corruption of the heap, which indicates a bug in myprogram.exe or any of the DLLs it has loaded.
This may also be due to the user pressing F12 while myprogram.exe has focus.
The output window may have more diagnostic information.
The text file contains numbers that i want to save in a double array, this is my code:
double* breakLine(char arr[])
{
double* row_data = new double[FILE_ROW_PARAMS];
int j= 0, m= 0,k= 0;
char str[FILE_ROW_SIZE];
while(arr[j] != '\0')//not end of line
{
if(arr[j] == ' ')//significant data
{
str[k] = '\0';
row_data[m++] = atoi(str);
k = 0;
}
else if(arr[j]!=' ')
{
str[k++] = arr[j];
if(arr[j+1] == '\0')
{
str[k] = '\0';
row_data[m] = atoi(str);
}
}
j++;
}
return row_data;
}
double* readFile(char fileName[],int* num,double* params)
{
int size= SIZE, number_of_lines= 0;
double* points = new double[SIZE * FILE_ROW_PARAMS];
char arr[128];
ifstream infile;
infile.open(fileName);
if(!infile)
{
cout<<"NO FILE!";
return NULL;
}
else
{
for(int i=0; i < NUMPARAM; i++) //get first params
{
infile >> params[i];
size--;
}
infile.getline(arr,128);
while(!infile.eof())
{
infile.getline(arr,128);
double* a = breakLine(arr);
for(int i=0; i < FILE_ROW_PARAMS; i++)
{
*(points+number_of_lines*FILE_ROW_PARAMS+i) = *(a+i);
}
number_of_lines++;
size--;
if(size == 0)
{
size = SIZE;
points = (double*)realloc(points, number_of_lines + SIZE * FILE_ROW_PARAMS);
}
}
infile.close();
*num = number_of_lines;
return points;
}
}