Character Problem
- Guru_
- Born


- Joined: Apr 22, 2009
- Posts: 2
- Status: Offline
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).
Code: [ Select ]
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;
}
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;
}
- 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;
- }
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
April 22nd, 2009, 6:11 pm
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 1 post
- Users browsing this forum: No registered users and 214 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
