I’m trying to code a program that displays letters in alphabetical order. It complies but the problem is that when it compiles, the letters [characters] don’t show up. The only thing the text file has is some random letters {A E C B D O).
int count(char input_filename[]);
void load_file(char input_filename[], int things[], int array_size);
void display(int things[], int array_size);
void bubble_sort(int things[], int array_size);
void pause(void);
char data_filename[] = "C:\\Data\\Letters.txt";
//************************************...
// main
//************************************...
int main(void)
{
int record_count = count_file_values(data_filename);
int acres[record_count];
load_file(data_filename, acres, record_count);
cout << "The letters are: \n";
display(acres, record_count);
bubble_sort(acres, record_count);
cout << "\n\nThe sorted letters are: \n";
display_array(acres, record_count);
pause();
return 0;
}
int count_file_values(char input_filename[])
{
fstream inData;
double next_value;
char number_of_values = 0;
inData.open(input_filename, ios::in);
if (!inData)
{
cout << "\n\nError opening input data file: " << input_filename << "\n\n";
pause();
exit(EXIT_FAILURE);
}
// Get data values and count them
while (inData >> next_value)
{
number_of_values++;
}
// Close the files
inData.close();
return number_of_values;
}
void load_file(char input_filename[], int things[], int array_size)
{
fstream inData;
inData.open(input_filename, ios::in);
if (!inData)
{
cout << "\n\nError opening input data file: " << input_filename << "\n\n";
pause();
exit(EXIT_FAILURE);
}
else
{
for (int i = 0; i < array_size; i++)
{
inData >> things[i];
}
inData.close();
}
return;
}
void display(int things[], int array_size)
{
for (char i = 0; i < array_size; i++)
{
cout << things [i] << " " ;
}
return;
}
void bubble_sort(int things[], int array_size)
{
bool moresortneeded;
int temp;
do
{
moresortneeded = false;
for(int i = 0; i < array_size - 1; i++)
{
if(things[i] > things[i+1])
{
temp = things[i];
things[i] = things[i+1];
things[i+1] = temp;
moresortneeded = true;
}
}
}
while(moresortneeded);
return;
}
void pause(void)
{
cout << "\n\n";
system("PAUSE");
cout << "\n\n";
return;
}