In my project, I want to count the elements of an array as follows:
struct Server{
uint sernum;
uint num;
uint data;
}
Server [] public datta;
function count() public constant returns(uint sercount) {
return datta.length;
}
function set_data (uint Sernum ,uint Num, uint Data ) public {
Server memory xserver = Server(Sernum,Num,Data);
uint x= count();
bool y;
if(x>=1){
for (uint i = 0; i<datta.length;i++){
if(datta[i].sernum == Sernum && datta[i].num==Num && datta[i].data<Data){
y=true;
}
else{
y==false;
}
}
if (y==true){
datta.push(xserver);
}
}
When I call a count function to see how many elements in the array it always gives me 1 no matter how many of the elements of the array
print( format(contract.functions.count().call()))
How do I count the elements of an array ??