ok guys I need your help. Im still new to C++ and what I need to do is read a .txt file into an array. The file consits of number like this ie 345 55555 56788765 5444 333 22 3 55656757 etc.... then I need to sort them using the bubble sort and resave them to the file after they are sorted. Ok my issue is writing the file into an array. I know how to do the bubbloe sort but cant get the array to work properly. I get it to read the txt file b/c i test with a cout but it goes to the last few numbers and i get a run time error about maxSize being used with about be initialized but it is. help
#include <iostream> // Need for cout,cin
#include <iomanip> // Need setf,fixed,showpoint,setprecision
#include <stdio.h> // Need for getchar
#include <fstream> // Needed for files
#include <cstdlib> // Needed for exit function
#include <string> // Need for string class
using namespace std;
string getInputFileName(); // a function to prompt for the complete file name
void bubblesort( string num,int maxSize);
int main ()
{
int maxSize;
string num;
//int num_array[501];
ofstream outFile;
ifstream inFile;
string fileName; // complete file name including the path
fileName = getInputFileName(); // prompt and obtain the full file name
// try to open the file
outFile.open(fileName.c_str(),ios_base::binary | ios::out| ios::app);
inFile.open(fileName.c_str(),ios_base::binary);
if(!outFile.is_open())
{
cerr << "File open Error Creating file" ;
cout << " Press enter to continue" << endl;
cin.ignore();
char ch = getchar();
exit(1);
}
if (!inFile.is_open())
{
cerr << "File open error " ;
cout << " Press enter to continue" << endl;
cin.ignore();
char ch = getchar();
exit (1);
}
while (!inFile.eof())
{
getline (inFile,num);
cout << num;
}
//int maxSize;
bubblesort(num,maxSize);
outFile.close();
inFile.close();
// keeps program opening till user enters a key
cout.setf (ios::showpoint );
cout.setf( ios::fixed);
cout << setprecision(2);
cout << "\n\n Press Enter to continue" << endl;
cin.ignore();
char ch = getchar();
return 0;
}
//************************************************************
//
// Function name: Search
//
// Purpose: Locate the ID the user entered. If found displays it with the name if not asks to enter into to the file
//
//
// Input parameters: string id, filehandle passed by reference (ifstream &inFile, ofstream &outFile)
//
// Output parameters: none
//
// Return Value:
//
//
//************************************************************
void bubblesort(string num,int maxSize )
{
int i,j;
for ( i=1; i< maxSize; i++)
{
for ( j = maxSize-1;j>=i;j--)
{
if(num[j] < num[j-1])
swap ( num[j-1],num[j]);
}
}
}
//************************************************************
//
// Function name: getInputFileName
//
// Purpose: to prompt for the fully qualified name of a file
// i.e. including the path of the file
//
// Input parameters: none
//
// Output parameters: none
//
// Return Value: a string containing the fully qualified name
// of a file
//
//************************************************************
string getInputFileName()
{
string f_Name; // fully qualified name of the file
cout << "Please enter the fully qualified name of the " << endl
<< "input text file (i.e. including the path): ";
cin >> f_Name ;
cout << endl; // skip a line
return f_Name;
}