I’m trying to code a program that displays the alphabet in alphabetical order. The file has the letters in random order and then I coded to where its in alphabetical order. The problem is when I compile, the letters don’t show up .I know I have to change the int to char and I did but I still don’t get the character letters to show up.
Code:
void load_array (char input_filename[], int things[], int array_size);
void display_array(int things[], int array_size);
void bubble_sort_array(int things[], int array_size);
void pause(void);
// Variables
char data_name[] = "C:\\Codes_Files\\Alphabet.txt";
//******************************************************
// main
//******************************************************
int main(void)
{
int record_count = count_file_values(data_filename);
int letters[record_count];
load_array_from_file(data_filename, letters, record_count);
cout << "randomized letters of the alphabet: \n";
display_array(letters, record_count);
bubble_sort_array(letters, record_count);
cout << "\n\nThe sorted alphabet: \n";
display_array(letters, record_count);
pause();
return 0;
}
// load_array
void load_array_from_file(char input_filename[], int things[], int array_size)
{
fstream inData;
inData.open(input_filename, ios::in);
if (!inData)
{
cout << "\n\nError opening file: " << input_filename << "\n\n";
pause();
exit(EXIT_FAILURE);
}
else
{
for (int i = 0; i < array_size; i++)
{
inData >> things[i];
}
inData.close();
}
return;
}
// display_array
void display_array(int things[], int array_size)
{
for (char i = 0; i < array_size; i++)
{
cout << things [i] << " " ;
}
return;
}
// bubble_sort_array
void bubble_sort_array(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;
}