Eh heres my entire code. I fixed that bug, except now I'm just plain getting frickin WEIRD stuff that I've no clue how to fix.....
Code:
#include <iostream>
#include <fstream>
#include <string>
#include <iomanip>
using namespace std;
// *** main *** ///////////////////////////////////////////////////////////////
int main (void)
{
ifstream fin; // Input file stream
ofstream fout; // Output file stream
bool continue_program = false; // Boolean to decide to continue or not
char ifile_name [90]; // Holds file name
bool open_input (ifstream& fin, char ifile_name[]);
bool open_output (ofstream& fout, char ifile_name[]);
void read_file (ifstream& fin, ofstream& fout);
// Loop calls open_input as long as continue_program is false
// Program continues after continue_program is true
while (!continue_program)
{
continue_program = open_input(fin, ifile_name);
} // while
continue_program = false;
// Loop calls open_output as long as continue_program is false
// Program continues after continue_program is true
while (!continue_program)
{
continue_program = open_output(fout, ifile_name);
} // while
read_file (fin, fout);
} // main
// *** open_input *** /////////////////////////////////////////////////////////
// Function opens the input file
bool open_input (ifstream& fin, char ifile_name[])
{
bool file_error = false;
cout << "Which input file do you want to open? ";
cin >> ifile_name;
fin.open(ifile_name);
// If file open fails, file_error set to true
if (fin.fail())
{
cout << "Unable to open input file" << ifile_name << endl;
file_error = true;
} // if
return file_error;
} // open_input
// *** open_output *** ////////////////////////////////////////////////////////
// Opens output file
bool open_output (ofstream& fout, char ifile_name[])
{
bool file_error = false;
char ofile[90];
cout << "Which output file do you want to open? ";
cin >> ofile;
// If output fails, file_error set to true
if (ofile == ifile_name)
{
cout << "Unable to open output file. Output file contains same name as "
<< "input.";
file_error = true;
} // if
return file_error;
} // open_putput
// *** read_file *** //////////////////////////////////////////////////////////
// Reads input file, then calls print_output
void read_file (ifstream& fin, ofstream& fout)
{
char character; // Holds a single character temporarily
char characters_encountered[80]; // Array to hold characters encountered
int character_count = 0; // Counts how many characters have been encountered
int null_count = 0; // Counts null characters
int character_encountered_counter[80]; // Array to hold how many characters of
// a type were encountered
void search_characters(int character_count, int null_count,
char character, char characters_encountered[],
int character_encountered_counter[]);
void print_output(int character_count, int null_count,
char characters_encountered[],
int character_encountered_counter[]);
// Loops continues until end of file
// Arrays are (hopefully) filled after loop
while (fin >> character)
{
++character_count; // Increase amount of characters read so far
search_characters(character_count, null_count, character,
characters_encountered, character_encountered_counter);
}
print_output (character_count, null_count, characters_encountered,
character_encountered_counter);
} // read_file
// *** search_characters *** //////////////////////////////////////////////////
// Searches for if character read has already been read before
void search_characters(int character_count, int null_count, char character,
char characters_encountered[],
int character_encountered_counter[])
{
int i = 0;
// Loop searches while i is less than characters counted so far
// The character found is either found to exist already, or is added
for (i = 0; i < character_count; i++)
{
// if (characters_encountered[i] == "\0")
// {
// ++null_count;
// } // if
if (characters_encountered[i] == character)
{
character_encountered_counter[i] += 1;
} // else if
else
{
characters_encountered[i+1] = character;
character_encountered_counter[i+1] = 1;
} // else
} // for
} // search_characters
// *** print_output *** ///////////////////////////////////////////////////////
// Prints arrays to output file
void (int character_count, int null_count, char characters_encountered[],
int character_encountered_counter[])
{
int i = 0;
fout << "NEW LINE OCCURED " << null_count << "TIMES" << endl;
// Loop writes data in arrays
// Data in arrays is written after completion
for (i = 0; i < character_count; i++)
{
fout << characters_encountered[i] << "OCCURED "
<< characters_encountered_counter[i] << setw(4) << "TIMES" << endl;
} // for
} // print_output
*Edit*
Maybe I should post the errors...
152: parse error before 'int' (152 is the function header for print_output)
162: syntax error before '<<' token (fout statement before for loop in print_output function)
165: character_count was not declared
165: parse error before ';' token
165: syntax error before '++' token