my program is suppose to count d number of occurrences of a chars in a file.
i just dont know how to store d occurences. this is wat i have done up to now.

#include <iostream>
#include <fstream>
using namespace std;

ifstream fin;
 	 void charactercount(int& w, char& s );
 void main()

{
//int sum[128];
int w;	
char s;
char charin;
char infile[20];

cout<< "enter file name"<< endl;
cin>> infile;
cout<<infile;

cout<< " " << endl;
	
	fin.open(infile);
	
	
	if ( fin.fail())
	 { 
		 cout<< " cannot find file" << endl;
		 exit(0);
	} 
else
{	
while(!fin.eof())
{
	fin.get(charin);

	w=static_cast<int>(charin);
	 s=static_cast<char>(w);
	 
	  }
	 //here i think i have to make a for loop that compares the position of i (from 0 to 127) with the value of w and 
	//	if they are equal add one to d occurrence of d position i

	   
	   

 }}}

Thanks for reading it .
i hope u understand wat i mean.

Thanks for reading it .
i hope u understand wat i mean.

Well, No. Have you abbreviated 'the' to 'd' in your sentences?

Are you trying to count the number of occurences of each character in the file? If so, you could store the count in a map, or even an array.

e.g. int count[256]; // the index is the character, the value is the count

and increment the counter in your loop: count[(unsigned char)charin]++

yes i use d for "the".

i will try that it .
i know very little about programming so i will study wat u told me thank u;

Well, No. Have you abbreviated 'the' to 'd' in your sentences?

Are you trying to count the number of occurences of each character in the file? If so, you could store the count in a map, or even an array.

e.g. int count[256]; // the index is the character, the value is the count

and increment the counter in your loop: count[(unsigned char)charin]++

commented: Well don't use 'd' for 'the' read the rules.. +0

hey;
thanks for d help but i still cant do it . can u explain a little bit better plz.

Sorry if you can't understand my notes above. Post what you've done so far and I'll see if can explain better.

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.