Answered You can hire a professional tutor to get the answer.

QUESTION

I have written a program that determines the frequency of letters in an input file.

I have written a program that determines the frequency of letters in an input file.

It works perfectly but the only problem is that the output file should put the characters in the order that they appear but they are being put in alphabetical order.

Please help.

Here is the code:

#include <fstream>

#include <iostream>

using namespace std;

int main()

{

   ofstream out;

   out.open("output.txt");

 ifstream input("input.txt", ios_base::binary);

 size_t count[256];

 fill_n(count, 256, 0);

 for (char c; input.get(c); ++count[uint8_t(c)])

  ;

 for (size_t i = 0; i < 256; ++i)

 {

  if (count[i] && isgraph(i))

  {

   out << char(i) << " " << count[i] << 'n';

  }

 }

 out.close();

}

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question