Character Problem

  • Guru_
  • Born
  • Born
  • Guru_
  • Posts: 2

Post 3+ Months Ago

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;
}
  1. int count(char input_filename[]);
  2. void load_file(char input_filename[], int things[], int array_size);
  3. void display(int things[], int array_size);
  4. void bubble_sort(int things[], int array_size);
  5. void pause(void);
  6. char     data_filename[] = "C:\Data\Letters.txt";
  7. //******************************************************
  8. // main
  9. //******************************************************
  10. int main(void)
  11. {
  12. int record_count = count_file_values(data_filename);
  13. int acres[record_count];
  14. load_file(data_filename, acres, record_count);
  15. cout << "The letters are: \n";
  16. display(acres, record_count);
  17. bubble_sort(acres, record_count);
  18. cout << "\n\nThe sorted letters are: \n";
  19. display_array(acres, record_count);
  20. pause();
  21. return 0;
  22. }
  23. int count_file_values(char input_filename[])
  24. {
  25. fstream inData;         
  26. double next_value;
  27. char     number_of_values = 0;
  28. inData.open(input_filename, ios::in);     
  29. if (!inData)
  30.     {
  31.     cout << "\n\nError opening input data file: " << input_filename << "\n\n";
  32.     pause();
  33.     exit(EXIT_FAILURE);
  34.     }
  35. // Get data values and count them
  36. while (inData >> next_value)
  37.     {
  38.     number_of_values++;
  39.     }
  40. // Close the files
  41. inData.close();                             
  42. return number_of_values;
  43. }
  44. void load_file(char input_filename[], int things[], int array_size)
  45. {
  46. fstream inData;         
  47. inData.open(input_filename, ios::in);     
  48. if (!inData)
  49.     {
  50.     cout << "\n\nError opening input data file: " << input_filename << "\n\n";
  51.     pause();
  52.     exit(EXIT_FAILURE);
  53.     }
  54. else
  55.     {
  56.     for (int i = 0; i < array_size; i++) 
  57.      {
  58.      inData >> things[i];
  59.      }
  60.     inData.close();
  61.     }
  62. return;
  63. }
  64. void display(int things[], int array_size)
  65. {
  66. for (char i = 0; i < array_size; i++)
  67.     {
  68.     cout << things [i] << " " ;
  69.     }
  70. return;
  71. }
  72. void bubble_sort(int things[], int array_size)
  73. {
  74. bool moresortneeded; 
  75. int temp;         
  76. do
  77.     {
  78.     moresortneeded = false;
  79.     for(int i = 0; i < array_size - 1; i++)
  80.      {
  81.      if(things[i] > things[i+1])
  82.         {
  83.         temp = things[i];
  84.         things[i] = things[i+1];
  85.         things[i+1] = temp;
  86.         moresortneeded = true;
  87.         }
  88.      }
  89.     }
  90. while(moresortneeded);
  91. return;
  92. }
  93. void pause(void)
  94. {
  95. cout << "\n\n";
  96. system("PAUSE");
  97. cout << "\n\n";
  98. return;
  99. }
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 73 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
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.