#include<string>
#include<iostream>
#include<sstream>
#include<fstream>
#include<algorithm>
//#include<vector>
using namespace std;
//function for max element in float array
float *findbiggest(float array[],int ival)
{
int counter, counter_max;
float aretheysame=0;
for(counter=0; counter < ival; counter++)
{
if (*(array+counter) > aretheysame)
{
aretheysame = *(array+counter);
counter_max = counter;
}
}
return(&*(array+counter_max));
}
//function for min element in float array
float *findsmallest(float array[],int ival)
{
int counter, counter_max=0;
float aretheysame=array[0];
for(counter=0; counter < ival; counter++)
{
if (*(array+counter) < aretheysame)
{
aretheysame = *(array+counter);
counter_max = counter;
}
}
return(&*(array+counter_max));
}
int main()
{
string filename,line;
int asize=1000;
float* array = new float[asize]; //you could also use vector<float> to have a dynamic array, so you
//wouldnt have to care about buffer-overflows and could do an easier input
cout << "Dateiname: ";
getline(cin,filename);
ifstream in(filename.c_str());
while(getline(in,line))
{
istringstream istr(line);
int ival = 0;
while(istr>>array[ival++])
{
if(ival==asize)
{ //buffer-overflow
float* ptmp = array;
array = new float[asize+=300];
copy(ptmp,ptmp+ival,array);
delete [] ptmp;
}
}
if(ival==0)
continue;
cout << "\nnumber of elements: " << ival << endl;
float *smallest = findsmallest(array,ival);
float *biggest = findbiggest(array,ival);
cout << "biggest: " << *biggest << " - address: " << (int)biggest
<< "\nsmallest: " << *smallest << " - address: " << (int)smallest << endl;
}
cin.ignore();
return 0;
}