I'm in a programming class and I have an assignment where I have to open a file, and count the number of times a certain character apperas that the user input, in that file. I need help in figuring out how to create a function to count the number of occurence of a give characeter, and with any mistakes that I may have made. So far this is what I have
#include "stdafx.h"
#include <iostream>
using namespace std;
// function to find the number of occurences of a character
int count_file(ifstream& in_file, int num);
int count_file(in_stream, out_stream);
int main()
{
int num, total;
//open file input
in_stream.open\("infile.txt"\);
if \(in_stream.fail\(\)\)
\{
cout << "opening input file failed" << endl
<< "program terminated" << endl;
exit\(1\);
\}
cout << "Enter a charcter that you would like to know whether or not it appears";
cin >> num;
// function to find the number of occurences of a character
count_file\(\)
//open file for output
out_stream.open\("outfile.txt"\);
count\_file\(in_stream, out_stream\);
// closing files
in_stream.close\(\);
out_stream.close\(\);
return 0;
}
int count_file(ifstream& in_file, int num)
{
while(! in_file.eof())
{
fin.get(num)
total =
}
}
// function to output the answer
int count\_file\(in_stream, out_stream\)
\{
cout << "The charcetr" << num << "occured" << total << "times";
\}