0
// SPDX-License-Identifier: GPL-3.0
pragma solidity >0.6.0 < 0.9.0 ;
contract xyz {
    uint256 public abc ;
    struct lmnop {
        uint256  abc;
        string name;
    }
    lmnop [] public qwerty ;
    //lmnop public qwerty = lmnop ({abc:2,name : "Nilesh Jain"});

function store (uint256 _abc) public 
{
    abc =_abc ;
    
}
function retrieve () public view returns (uint256)
{
    return abc ;
}
function addqwerty (string memory _name, uint256 _abc) public {
 lmnop.push(lmnop({abc:_abc, name:_name})) ;
}
}

tried to changing as the code provided in exchange but it does not work.

1 Answer 1

1

The array you declare here :

 lmnop [] public qwerty ;

is of type lmnop[] and has a name / identifier of qwerty. Simply change your addqwerty function to use the actual name of the array instead of its type :

function addqwerty (string memory _name, uint256 _abc) public {
 qwerty.push(lmnop({abc:_abc, name:_name})) ;
}
3
  • Thank you so much!!!! I was getting crazy over this. Am a newbie and want to learn solodity as my first language, thank you so much for helping me in it!!! Commented May 10, 2022 at 7:33
  • By the way can you please recommend me some resources to study solidity? Currently watching frrecodecamp's video for some knowledge gain Commented May 10, 2022 at 7:39
  • You have @Patrick Collins class on freecodecamps , it's certainly enough to get you started, but maybe that's the one you are already doing... Just make some projects and learn as you go. The documentation is really helpful, and you can always ask questions on Stack Exchange if you are stuck. I'd argue that CTF such as Capture The Ether and Ethernaut are also helpful, as they often require some deeper knowledge of the language / EVM which cannot really hurt, plus they are fun to do !
    – hroussille
    Commented May 12, 2022 at 6:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.