Hi,
have tryed and everything below gives me 0
sizeof(array) / sizeof(*array);
sizeof(array) / sizeof(array[0]);
sizeof(array) / sizeof(array data type);
//even the thing which i do not understant:
template< typename T, std::size_t N > inline
std::size_t size( T(&)[N] ) { return N ; }
I need to get the size of pointer array..
here is the whole code:
#include <iostream>
#include <string>
#include <stdlib.h>
#include <fstream>
using namespace std;
//
double * dSM = NULL, * temp;
//
void GaunamDuomenis(string sF);
double TeigiamuVidurkis(double dMasyvas[]);
//
int main ()
{
string sFP;
cout << "Filename:\n";
cin >> sFP;
GaunamDuomenis(sFP);
cout << "Arithmetical mean of positive numbers: " << TeigiamuVidurkis(dSM) << endl;
return 0;
}
//
void GaunamDuomenis(string sF)
{
string sS;
ifstream ifsF(sF.c_str());
if (!ifsF)
{
cout << "OOOps couldn't open..\n";
}
else
{
int i = 0;
while (getline(ifsF, sS, ' '))
{
i++;
temp = (double*) realloc(dSM, i * sizeof(double));
if (temp != 0)
{
dSM = temp;
dSM[i-1] = atof(sS.c_str());
}
}
}
}
//
double TeigiamuVidurkis(double dMasyvas[]) // Need to get length of dMasyvas
{
double dS = 0, dV = 0;
int iMI; // variable for the size of array
cout << iMI << endl;
for (int i = 0; i < 5; i++)
{
if (dMasyvas[i] > 0)
{
dS += dMasyvas[i];
}
}
dV = dS / 5;
return dV;
}