Once I do cancel some data from a struct, how do I remove the empty cells that I then create? Sorry for the silly question but I am just new :)
Below you will see "function removeAppointment" where, given a year, it cancels al the appointments that contain that year. I then remain with empty spaces in my struct that I would like to remove.
pragma solidity ^0.5.14;
contract Calendario_Appuntamenti {
mapping (uint => calendar) public appointment;
address owner;
uint256 public _counter = 0;
constructor ()public{
owner = msg.sender;
}
modifier only0wner(){
require (msg.sender == owner);
_;
}
struct calendar{
uint256 _id;
uint256 _day;
string _month;
uint256 _year;
}
function addAppointment (uint256 _day, string memory _month, uint256 _year) public{
_counter +=1;
appointment [_counter] = calendar (_counter,_day,_month,_year);
}
function removeAppointment (uint256 _yeartoremove) public only0wner {
uint256 _i;
_i = _counter;
while (_i > 0){
if(_yeartoremove == appointment [_i]._year){
delete (appointment [_i]);
}
_i -=1;
}
}
}