954,500 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

need help

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.

Bigboy06
Newbie Poster
15 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 
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]++

dougy83
Posting Whiz in Training
275 posts since Jun 2007
Reputation Points: 85
Solved Threads: 45
 

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]++

Bigboy06
Newbie Poster
15 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

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

Bigboy06
Newbie Poster
15 posts since Sep 2008
Reputation Points: 10
Solved Threads: 0
 

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

dougy83
Posting Whiz in Training
275 posts since Jun 2007
Reputation Points: 85
Solved Threads: 45
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You