Accessing .dat files within a folder
Below, I have c/p my code. The program is supposed to input a folder name, and inside that folder there are two .dat files with an array of data in each that I am supposed to read and output the average and the maximum values in each. Can someone help me out please? Also, I do not know what to include in my arguments in my first three function definitions...because when I uncomment my function calls, I get errors that refer to those function arguments. Please help ASAP! Thank you in advance for all the help!
Code:
#include <sys/types.h>
#include <dirent.h>
#include <errno.h>
#include <vector>
#include <string>
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <cstring>
using namespace std;
typedef vector<string> stringVector; //Defines a vector of string values
const int MAX_SIZE = 31;
void OpenInputFile(ifstream& in_file, char string);
void OpenOutputFile(ofstream& out_file, char string);
int ReadArray(ifstream& in_file, int number[]);
float CalcAverage(int array[]);
float CalcMax(int array[]);
int getDir(string dir, stringVector &files);
int main()
{
ifstream indiv_file;
ofstream out_file;
int count = 0, array[MAX_SIZE], next;
float average_temp, maximum_temp;
int start;
string dir, intro, compound;
intro = "C://*/*/*/*/*/*/*/";
cout << "Enter directory with files available for use: "; //Lists the files in the current directory you could input .
cin >> dir;
compound = intro + dir;
stringVector files = stringVector();
/*cin >> InputFiles/;
string dir;
get_Dir() --> files[size]
ifstream ifs;
ifs.open("path+numbers.dat")
open((dir+files[i]).c_str())*/
getDir (dir, files);
for (unsigned int count = 0; count < files.size(); count++)
{
if (files[count].at(0)!= '.') // if the file is a valid file
{
//indiv_file.open((compound + files[i]).c_str());
indiv_file.open((dir + files[count]).c_str());
cout << endl << dir + " " + files[count] << endl;
for (int j = 0; j < count; j++)
{
while (indiv_file >> next)
{
cout << array[j];
j++;
}
cout << array[j] << " " << endl;
}
if(count == MAX_SIZE)
break;
}
indiv_file.close();
}
//OpenInputFile (array, string);
//OpenOutputFile (out_file, string);
//ReadArray (in_file, number[]);
average_temp = CalcAverage(array);
maximum_temp = CalcMax(array);
cin >> start;
return 0;
}
int getDir (string dir, stringVector &files)
{
DIR *dp;
struct dirent *dirp;
if((dp = opendir(dir.c_str())) == NULL) {
cout << "Error(" << errno << ") opening " << dir << endl;
return errno;
}
while ((dirp = readdir(dp)) != NULL) {
files.push_back(string(dirp->d_name));
}
closedir(dp);
return 0;
}
void OpenInputFile(ifstream &in_file, int string)
{
char symbol;
ifstream in;
in.open("January.dat");
if (in.fail())
{
cout << "Failed to open file." << endl;
exit(1);
}
do
{
cin.get(symbol);
cout << symbol;
} while (symbol != '.');
in.open("February.dat");
if (in.fail())
{
cout << "Failed to open file." << endl;
exit(1);
}
}
void OpenOutputFile(ofstream &out_file, int string)
{
ofstream out;
out.open("MaxOfArrays.txt");
out_file.open("AveragesOfArrays.txt");
}
int ReadArray(ifstream &in_file, int number[])
{
int next;
ifstream in;
while (in >> next)
{
cout << next;
}
return 0;
}
float CalcAverage(int array[])
{
int average, total = 0, i = 0;
for (i; i < MAX_SIZE; i++)
{
total += array[i];
}
average = (total / i);
return 0;
}
float CalcMax(int array[])
{
return 0;
}