Guys, in this program, we have a file by the name of asharray.txt, which is attached to this post, and we have three functions:
1.to read the file
2.to sort the numbers
3.to write to a separate file by the name of( array result.txt)
Sp, here I faced some problems, in the third function and I am not able to figure it out, so guys anyone who can resolve ma doubt..............
#include <cstdlib>
#include <iostream>
#include <fstream>
using namespace std;
void fileread(int array[],int &counter)
{
ifstream fin;
counter=0;
int number;
fin.open("asharray.txt");
if(fin.fail())
{
cout<<" The file dose not exist " << endl;
system("PAUSE");
}
while(!fin.eof())
{
counter ++;
fin>>array[counter];
if(fin.fail())
{
cout<<" There is some error with the variable declaration "<< endl;
system("PAUSE");
}
}
fin.close();
}
void sorting(int array[], int size)
{
int i,j;
int temp;
for(i=0;i<size;i++)
{
for(j=i+1;j<size;j++)
{
if(array[i]<array[j])
{
temp=array[i];
array[i]=array[j];
array[j]=temp;
}
}
}
cout<< " THE SORTED ARRAY ARE " << "array [" << i <<"] = " << array[i] << endl;
}
void writetofile(int array[],int size)
{
ofstream fout();
int i;
fout.open("array result.txt");// error request for member `open' in `fout', which is of non-class type `std::ofstream ()()'
fout<<" The sorted array is "<< endl;
for(i=0;i<size;i++)
{
fout<<array[i];
}
}
int main(int argc, char *argv[])
{
int size=10;
system("PAUSE");
return EXIT_SUCCESS;
}