434,793 Members | 1,257 Online
Need help? Post your question and get tips & solutions from a community of 434,793 IT Pros & Developers. It's quick & easy.

# Will this code be faster using stdio???

 P: n/a 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:sa*******@gmail.com #include #include #include 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)<< " "<