hello all

please help .. whenever I enter a path it tells me it cannot open the file

here is the code:

# include <iostream>
# include <fstream>
# include <iomanip>

using namespace std;

struct count_type
{
	int count;
	double percent;
};

void intial_struct(count_type count[]);
void open_file(ifstream&, ofstream&);
void counter(count_type count[], ifstream& in);
void print(ofstream&, count_type count[]);


int main()
{
	count_type count[2];

	ifstream in;
	ofstream out;

	cout<<"WELCOME: you can count the letters in your file"<<endl;
	
	//to intialize the struct array
	intial_struct(count);
	//to open the files
	open_file(in,out);
	//calling the counter
	counter(count, in);
	//prints the results
	print(out, count);

	//closes file streams
	in.close();
	out.close();

	return 0;
}

void intial_struct(count_type count[])
{
	for (int i=0; i<2; i++)
	{
		count[i].count=0;
		count[i].percent=0.0;
	}
}

void open_file(ifstream& in, ofstream& out)
{
	char input_name[90];

	cout<<"Please enter the name of the input file"<<endl;
	cin>>input_name;

	in.open(input_name);

	if(!in)
	{
		cout<<"\aError opening the input file"<<endl;
		exit(0);

	}

	if(!out)
	{
		cout<<"\aError opening the output file"<<endl;
		exit(0);

	}
}

void counter(count_type count[], ifstream& in)
{
	char ch;

	while(!cin.eof())
	{

	cin>>ch;

	if (ch>=97 && ch<=123)
		count[0].count++;

	else if (ch>=65&& ch<=90)
		count[1].count++;
	}
	
}

void print(ofstream& out, count_type count[])
{
	int countin=count[0].count+count[1].count;

	for(int i=0; i<2; i++)
		count[i].percent=(count[i].count*100)/countin;

	out<<"There are total " <<countin<<" letters in your file"<<endl;
	out<<count[0].count<<"percent of them is small letter"<<endl;
	out<<count[1].count<<"percent of them is capital letter"<<endl;

	out<<"Your result are in the file you specified"<<endl;
	out<<"Thank you"<<endl;
}

please help

Look closely at line 69. What value has out at that moment?

what do you mean?

do you mean what is in the file?

but it says i have an error before I reach that point

I mean you do in.open() , but don't do out.open() .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.