Question: // segmanation core dump, can not figure out why? #include #include #include #include #include #include #include #include #define SIZE 2000 using namespace std; float averageAbsorbanceValue(float
// segmanation core dump, can not figure out why?
#include
float averageAbsorbanceValue(float absorbances[], int totalRecords) // declarin\ g function { float sum = 0.0; for(int i=0;i float stdv(float absorbances[], int totalRecords) // declaration of standdeviat\ ion function { float sum = 0.0,stdv = 0.0; float averageAbsorbance = averageAbsorbanceValue(absorbances, totalRecords); for(int i = 0; i < totalRecords; i++) // for loop to calculate stdv for array { stdv = stdv+pow(absorbances[i]-averageAbsorbance,2); } return sqrt(stdv/totalRecords); } int main() { ifstream stdvFile; // declaring file name string filename = "nir_090202_tolmetinblends-000001.dat"; // reading .dat stdvFile.open(filename.c_str(), ios::in); if(stdvFile.fail()) // inform user if file could not be opened { cout << "A file by that name was not found "; exit(1); } cout << "The file has been successfully opened for reading. " << endl; // int wavelengths[SIZE]; float absorbances[SIZE]; int totalRecords=0,check=1,i=0,j=0; string temparray[SIZE]; string linebuffer; string reference; while (stdvFile && getline(stdvFile, linebuffer)) { if (linebuffer.length() == 0)continue; std::istringstream stream(linebuffer); if(check==1) { stream>>reference; if(reference=="**HeaderEnd**") { check=0; } j++; } else { stream >> wavelengths[i] >> absorbances[i]; totalRecords++; i++; } } float average=averageAbsorbanceValue(absorbances,totalRecords); float std=stdv(absorbances,totalRecords); float resultarray[totalRecords]; for(int i=0;i return 1; } fout< fout.close(); } // segmantation core dump, cant figure out why
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
