I cant figure out how to fix the errors in this prooram. Any help would be great.
// date: April 25, 2008
// username: dpfaff
#include <cstring>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <iostream>
using namespace std;
const int MAXCHARS = 25;
const int MAXSIZE = 6;
typedef char String [MAXCHARS];
string array[MAXSIZE];
// opens an input file called in.dat
// outputs: if no failure, infile is open
// else prints message and program stops
// usage: openInputFile (infile);
void openInputFile (ifstream& infile);
// sorts a list of words
// inputs: array[0..size-1]
// outputs: array
// usage: selectionSort (nums, MAXSIZE);
void selectionSort (string array[], int size);
// enters a list of words
// inputs: a list of words
// outputs: a list of words in array
// usage:
void enter (ifstream& infile, string array[], int size);
// prints a list of words
// inputs: a list of words in array
// outputs: a list of words separated by commas
// usage:
void print (string array[], int size);
// prints a number of new lines
// inputs: num, the number of new lines
// outputs: num new lines
// usage: printNewLines(3);
void printNewLines (int num);
int main()
{
ifstream infile;
openInputFile (infile);
openInputFile(inlab.dat);
string array [MAXSIZE];
enter (inlab.dat, array, MAXSIZE);
print (array, MAXSIZE);
printNewLines(3);
selectionSort (array, MAXSIZE);
print (array, MAXSIZE);
inlab.dat.close();
return 0;
}
void selectionSort (string array[], int size)
{
int start, minIndex, minValue;
for (start = 0; start < size - 1; start++)
{
minIndex = start;
strcpy(minValue, array[start]);
for (int index = start + 1; index < size; index++)
{
if (strcmp(array[index], minValue) < 0))
{
strcpy(minValue, array[index]);
minIndex = index;
}
}
strcpy(array[minIndex], array[start]);
strcpy(array[start], minValue);
}
}
// opens an input file called in.dat
// outputs: if no failure, infile is open
// else prints message and program stops
// usage: openInputFile (infile);
void openInputFile (ifstream& infile)
{
infile.open("inlab.dat");
if (infile.fail())
{
cout << "Error opening input file" << endl;
exit(1);
}
}
// enters a list of words
// inputs: a list of words
// outputs: a list of words in array
// usage:
void enter (ifstream& infile, string array[], int size)
{
for (int i = 0; i < size; i++)
{
infile >> array[i];
}
}
void print (ifstream& infile, String array[], int size)
{
printNewLines(2);
for (int i = 0; i < size; i++)
cout << array[i] << ", ";
printNewLines(2);
}
// prints a number of new lines
// inputs: num, the number of new lines
// outputs: num new lines
// usage: printNewLines(3);
void printNewLines (int num)
{
for (int k = 0; k < num; k++)
cout << endl;
}