S
samoukos
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:[email protected]
#include<iostream>
#include<cstdlib>
#include<fstream>
using std::ifstream;
using std:
fstream;
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=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>max)
{
max=sum;
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;
}
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:[email protected]
#include<iostream>
#include<cstdlib>
#include<fstream>
using std::ifstream;
using std:
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=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>max)
{
max=sum;
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;
}