Question
this program read and count only a latter from text file, but i need this program read and count each words from text file. can
this program read and count only a latter from text file, but i need this program read and count each words from text file. can you fix it please!
for example: if the text file is " I am cs 162 student. I also work at Downtown",
the out put would be:
I - 2 time
am - 1 time
cs - 1 time
162 - 1 time...........etc
#include "main.h" // header file for this module
// Function Definitions int main(int argc, char **argv)
// Stack variables int count_table[256] = {0}; // Table of character counts. // Subscript: ASCII character code char byte = '\0'; // Input buffer std::fstream file; // Input file stream std::string file_name; // Input file name
// Get the input file name if (argc < 2) { std::cout << "Enter input file name: "; std::getline(std::cin,file_name); } else { file_name = argv[1]; }
// Open the file stream file.exceptions(std::fstream::failbit); // Generate exception if error try { file.open(file_name, std::ios::in); // Open for input } catch (const std::exception & exception_object) { std::cout << "?Exception opening \"" << file_name << "\": " << exception_object.what() << std::endl; return 1; }
// Count characters while(file.peek() != EOF) { byte = file.get(); count_table[static_cast
file.clear(); file.close();
// Display character count for (int index = 0; index < 256; index++) { if (count_table[index] > 0) { std::cout << "Code " << std::setw(3) << std::setfill(' ') << index << " "; if (index > ' ') { std::cout << "('" << static_cast
// All done return 0; }
main.h
// System Libraries #include
// Function Declarations int main(int, char**); // Main function
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started