Disclaimer that I've never worked with files before, so there's probably a lot more issues in this code than the void error. I can't even get the program to compile to find those errors though, so I'd appreciate insight into why I'm having this issue. Files are separated into .hpp and .cpp files for the assignment.
/***************************
Description: Reads a file filled with letters, counts the letter frequencies in the file, writes the results to a new file (one new file per line)
***************************/
#include "count_letters.hpp"
#include "output_letters.hpp"
#include <cctype>
#include <iostream>
#include <fstream>
#include <string>
int main()
{
std::ifstream inputFile;
std::ofstream outputFile;
//get name of desired file from user
std::cout << "Name the file you'd like to read:" << std::endl;
std::string inputFileName;
std::cin >> inputFileName;
//open the file
inputFile.open(inputFileName);
while(!inputFile) //while file name doesn't exist
{
std::cout << "ERROR: Re-enter file name," << std::endl;
std::cin >> inputFileName;
inputFile.open(inputFileName);
}
if (inputFile) //if file successfully opens
{
while (inputFile.peek() != EOF)
{
//create an array to pass to functions
constint LETTERS = 26; //will count frequency of the 26 letters
int array[LETTERS] = {0}; //every frequency begins at 0
//call the functions
count_letters(inputFile, array);
output_letters(outputFile, array);
inputFile.close(); //close the file
}
}
else
{
std::cout << "Could not access file." << std::endl;
}
return 0;
}
/***************************
Description: Takes an input file stream variable and a pointer to an array of integers as parameters.
*Reads the paragraph string from the input file stream
*Counts the letter frequencies in the paragraph
*Stores the frequencies in the array
*Disregards upper/lowercase letters
***************************/
#include <iostream>
#include <string>
#include <fstream>
#include "count_letters.hpp"
void count_letters(std::ifstream& inputFile, int* array);
{
std::string = reading;
//reads line and store data in reading
getline(inputFile, reading);
int max=reading.length(); //counts how many letters in line
//32 spaces between caps and lower in acsii table, 65=A, 97=a
for (length=0; length<max; length++)
{
for (count=0; count<26; count++)
{
char ch = reading.get();
if (ch>64 && ch<90) //if uppercase
{
ch+=32; //change to lowercase
array[ch-97]++;
}
else
{
array[ch-97]++;
}
}
}
}
/***************************
Description: Takes an ouput file stream variable and a pointer to an array of integers THAT CONTAINS FREQUENCIES OF LETTERS as parameters
*Asks user for the filename the user wants to output to
*outputs the frequencies of letters to the output file
***************************/
#include <iostream>
#include <string>
#include <fstream>
#include "output_letters.hpp"
void output_letters(std::ofstream& outputFile, int* array)
{
std::string outputFileName;
char alphabet;
//name and open output file
std::cout << "What file would you like to output to?" << std::endl;
std::cin >> outputFileName;
outputFile.open(outputFileName);
for(int count=0; count<26; count++)
{
alphabet = (count+97);
outputFile << alphabet << ": " << array[count] << std::endl;
}
for(int count2=0; count2<26; count2++)
{
array[count]=0; //reset array for next round of counting
}
outputFile.close(); //close file
}
Watch out for extra semicolons where they don't belong.
In future please post all your error messages, exactly as they appear in your development environment, you should have multiple errors in your present code.