need help

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2008
Posts: 13
Reputation: Bigboy06 is an unknown quantity at this point 
Solved Threads: 0
Bigboy06 Bigboy06 is offline Offline
Newbie Poster

need help

 
0
  #1
Sep 6th, 2008
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.
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. ifstream fin;
  6. void charactercount(int& w, char& s );
  7. void main()
  8.  
  9. {
  10. //int sum[128];
  11. int w;
  12. char s;
  13. char charin;
  14. char infile[20];
  15.  
  16. cout<< "enter file name"<< endl;
  17. cin>> infile;
  18. cout<<infile;
  19.  
  20. cout<< " " << endl;
  21.  
  22. fin.open(infile);
  23.  
  24.  
  25. if ( fin.fail())
  26. {
  27. cout<< " cannot find file" << endl;
  28. exit(0);
  29. }
  30. else
  31. {
  32. while(!fin.eof())
  33. {
  34. fin.get(charin);
  35.  
  36. w=static_cast<int>(charin);
  37. s=static_cast<char>(w);
  38.  
  39. }
  40. //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
  41. // if they are equal add one to d occurrence of d position i
  42.  
  43.  
  44.  
  45.  
  46. }}}
Thanks for reading it .
i hope u understand wat i mean.
Last edited by cscgal; Sep 6th, 2008 at 2:38 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: need help

 
0
  #2
Sep 6th, 2008
Originally Posted by Bigboy06 View Post
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]++
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: Bigboy06 is an unknown quantity at this point 
Solved Threads: 0
Bigboy06 Bigboy06 is offline Offline
Newbie Poster

Re: need help

 
-1
  #3
Sep 6th, 2008
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;

Originally Posted by dougy83 View Post
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]++
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 13
Reputation: Bigboy06 is an unknown quantity at this point 
Solved Threads: 0
Bigboy06 Bigboy06 is offline Offline
Newbie Poster

Re: need help

 
0
  #4
Sep 6th, 2008
hey;
thanks for d help but i still cant do it . can u explain a little bit better plz.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 275
Reputation: dougy83 is on a distinguished road 
Solved Threads: 45
dougy83 dougy83 is offline Offline
Posting Whiz in Training

Re: need help

 
0
  #5
Sep 6th, 2008
Sorry if you can't understand my notes above. Post what you've done so far and I'll see if can explain better.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the C++ Forum
Thread Tools Search this Thread



Tag cloud for C++
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC