I have a program to read in words and sort those words into lexicographical order. The problem I have is that it reads the input file endlessly. I know it does not reach the output section because the output file is not created.
Code:
size_t maxArraySize = 1000;
int main (int argc, char* argv[])
{
char* a [maxArraySize];
unsigned int count = 0;
if (argc < 3) //checks to make sure user enter input/output files
{
std::cout << "Enter two files for input and output!" << std::endl;
std::cout << "Example: stringsort.x infile outfile. Exiting..." << std::endl;
exit(1); //exits if input/output file not entered
}
char buffer[256];
std::ifstream inFile(argv[1]);
while (!inFile.eof()) && count < maxArraySize)
{
inFile.getline (buffer,100);
a[count] = buffer;
count++;
}
school::g_merge_sort(a, a + count);
unsigned int i = 0;
std::ifstream outFile (argv[2]);
if (! outFile.is_open())
{
std::cout << "Error opening file";
exit (1);
}
while (! outFile.eof() )
{
std::cout << a[i] << std::endl;
++i;
}
return 0;
}
Comment