Skip to content
Snippets Groups Projects
Commit 97713936 authored by Fabio Roberto Vitello's avatar Fabio Roberto Vitello
Browse files

added testMatrix

Simple code to compare the output of two file
parent a18c2291
No related branches found
No related tags found
No related merge requests found
File added
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
int main(int argc, char *argv[])
{
ifstream myfile(argv[1]);
ifstream myfile1(argv[2]);
ofstream outfile("res.txt");
if (myfile.is_open() && myfile1.is_open())
{
int arrSize = 0;
double arr[1001805]; // Ideally this would be a vector, but you said array
double arr1[1001805]; // Ideally this would be a vector, but you said array
double res[1001805]; // Ideally this would be a vector, but you said array
while ( true)
{
double x;
myfile >> x;
if (myfile.eof())
break;
arr[arrSize++] = x;
}
arrSize=0;
while (true)
{
double x;
myfile1 >> x;
if (myfile1.eof())
break;
arr1[arrSize] = x;
res[arrSize]=arr[arrSize]-arr1[arrSize];
outfile<<arrSize<<" "<<fixed<<setprecision(20)<< res[arrSize]<<" "<<arr[arrSize]<<" "<<arr1[arrSize]<<"\n";
arrSize++;
}
// I should have closed the file here, but as the program was ending I was lazy }
}
else
{
cout << "Unable to open file";
}
outfile.close();
myfile.close();
myfile1.close();
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment