I just did that and it still comes up. I think it has to do with the opening of the file because if I remove the fscanf line, the error message doesn't come up.
the error is that at a place where the
stream was expected to be NULL, it is not NULL. stream (in the FILE structure)
would be NULL after the file has been closed.
remember that fscanf can corrupt memory if your format specifiers are incorrect.
Last edited by vijayan121; Apr 8th, 2007 at 4:06 pm. Reason: formatting
if (temp_each_day = NULL)
printf("Error opening input file. \n");
The = in the above code should be replaced by == if what you want to do is comparision.
that is clearly the error. once you assign NULL to temp_each_day,
a. the if block will not execute.
b. fclose(NULL) will assert and an assertion wil fail on exit if fclose is not called.
Last edited by vijayan121; Apr 8th, 2007 at 4:11 pm. Reason: format
the compiler would have given a warning for this.
tip: set the warning level of the compiler to the highest available, and pay attention to the warnings.
you would save yourself a great deal of effort and time.
Last edited by vijayan121; Apr 8th, 2007 at 4:21 pm. Reason: format
This code shows assertion failure after setting and displaying the matrix values
//C++ class to get matrix elements as input from user
class matrix_input
{
private:
int nof_row,nof_column;
int row_count,column_count;
int nof_matrix;
int **address;
public:
matrix_input();
int get_no_row();
int get_no_col();
int mat_elem_memalloc();
int getmatrix();
void show_matrix();
~matrix_input();
};
#include "matrix_input.h"
#include <iostream>
using namespace std;
//
matrix_input::matrix_input()
{
nof_row=0;
nof_column=0;
row_count=0;
column_count=0;
}
//
int matrix_input::get_no_row()
{
int no_row;
cout<<"Enter the no of rows in matrix\n";
cin>>no_row;
nof_row=no_row;
return nof_row; //the last overwrited value
}
//
int matrix_input::get_no_col()
{
int no_col;
cout<<"Enter the no of columns in matrix\n";
cin>>no_col;
nof_column=no_col;
return nof_column; //the last overwrited value
}
//
int matrix_input::mat_elem_memalloc()
{
int **ptr,i;
ptr=new int*[nof_row];
for(i=0;i<nof_row;i++)
{
ptr[i]=new int[nof_column];
}
address=ptr; //* to * or ** to ** is possible
return **address; //In return * or ** symbol should be added in pointers
//dummy return value
}
//
int matrix_input::getmatrix()
{