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++
Will this code be faster using stdio???
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: 3422775"] Hello i had to do this project but at school they tell me that it will be faster using stdio insteed of fstream... Is that right??? if it is faster can anyone suggest how this code will be using stdio???thank you???? here is the code: //Made by Samuel Johnson //email:sammojohn@gmail.com #include<iostream> #include<cstdlib> #include<fstream> using std::ifstream; using std::ofstream; using std::endl; using std::ios; int main () // Lawdy, Lawdy I do declare! { ifstream fin; ofstream fout; int i,j,max,imax; char rod; int sum[255]; fin.open("friktories.in"); fout.open("friktories.out"); //---------------------------------- // Initializes array for summing // ASCII (extended) characters for (i=0;i<255;i++) { sum[i]=0; } //---------------------------------- // Reads file one char @ a time // into char var rod, then sums it // in array sum with index rod // // can this be faster using stdio? // while (!fin.eof()) { rod=fin.get(); sum[rod]=sum[rod]+1; } //---------------------------------- // Finds max frequency in sum array, // writes it to output file, // zeros the value in sum array, // and repeats for all ASCII char // that we are interested in. Includes // ASCII 32 (space) // // max=-1; for (j=0;j<27;j++) { for (i=97;i<124;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]=-1; max=-1; } //---------------------------------- // Closes the files nicely! fin.close(); fout.close(); fout << endl; return 0; }[/i][/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Will this code be faster using stdio???
Top