Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
CODE CHECK.!!
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="samoukos, post: 3421572"] HELLO .... I WROTE THIS CODE .... IT'S PORPOSE IS TO READ A GREEK TEXT USING ASCII CODING AND THEN COUNTING HOW MANY TIMES EACH WORD APPEARS...THEN IT MUST PRINT IT OUT WITH ASCEDING SEQUENCE.. CAN YOU PLEASE CHECK THIS CODE AND TELL ME IF THERE ARE ANY MODIFICATIONS THAT CAN BE MADE IN ORDER TO MAKE IT FASTER AND BETTER...THANK YOU.... HERE IS THE CODE:: #include<iostream> #include<cstdlib> #include<fstream> using std::ifstream; using std::ofstream; using std::endl; using std::ios; int main () { ifstream fin; ofstream fout; int i,j,q,NumberUsed,max,imax; char alpha[1000000]; int sum[255]; fin.open("TEXT.txt"); fout.open("TEXT.out"); //----------------------------------- for (i=0;i<1000000;i++) { alpha[i]=0; } //---------------------------------- for (i=0;i<255;i++) { sum[i]=0; } //---------------------------------- //---------------------------------- i=0; while (!fin.eof()) { alpha[i]=fin.get(); i++; } NumberUsed=i; //---------------------------------- for (i=0;i<NumberUsed;i++) { q=alpha[i]; //cout << q << endl; sum[q]=sum[q]+1; //cout << sum[q]<< endl; } //---------------------------------- // Displays ascii values as entered // used for tracing //for (i=0;i<NumberUsed;i++) //{ //fout << alpha[i]+1-1 << " "; //} //---------------------------------- // // Outputs character frequency //for (i=0;i<255;i++) //{ //fout << i <<" "<< sum[i]<<endl; //} //---------------------------------- max=0; for (j=0;j<26;j++) { for (i=97;i<122;i++) { if (sum[i]>max) { max=sum[i]; imax=i; } } if (sum[32]>max) { max=sum[32]; imax=32; } fout << char(imax)<< " "<<sum[imax]<<endl; sum[imax]=0; max=0; } //---------------------------------- fin.close(); fout.close(); fout << endl; return 0; }[/i][/i][/i][/i][/i][/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
CODE CHECK.!!
Top