| | |
need help
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Sep 2008
Posts: 13
Reputation:
Solved Threads: 0
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.
Thanks for reading it .
i hope u understand wat i mean.
i just dont know how to store d occurences. this is wat i have done up to now.
C++ Syntax (Toggle Plain Text)
#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 }}}
i hope u understand wat i mean.
Last edited by cscgal; Sep 6th, 2008 at 2:38 pm. Reason: Added code tags
•
•
Join Date: Jun 2007
Posts: 275
Reputation:
Solved Threads: 45
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:
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]++ •
•
Join Date: Sep 2008
Posts: 13
Reputation:
Solved Threads: 0
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;
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]++
![]() |
Other Threads in the C++ Forum
- Previous Thread: Recursive function not fully working
- Next Thread: Creating a query
| Thread Tools | Search this Thread |
Tag cloud for C++
api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll dynamiccharacterarray email encryption error file format forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lib list loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project python random read recursion recursive reference return rpg sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets





