0

If the set function receives two inputs

1.["0xca35b7d915458ef540ade6068dfe2f44e8fa733c",50,"ROC","park"]

2.["0x14723a09acff6d2a60dcdf7aa4aff308fddc160c",60,"AU","school"]

How do I display the string position in an array?(ex:["ROC", "AU"]), because I want to use time, location and position to do some if-else statement and then return the results to the user. thanks

pragma solidity ^0.5.1;

contract matching {

    struct User {
        uint time;
        string location;
        string position;
    }
    User[] people; 

    mapping (address => User) user_mapping;
    address[] public userAccounts;

    function set(address _address, uint _time, string memory _location, string memory _position) public {
        User storage users = user_mapping[_address];

        users.time = _time;
        users.location = _location;
        users.position = _position;

        userAccounts.push(_address) -1;
    }

    function getAccounts()public view returns(address[] memory) {
        return userAccounts;
    }

    function getInfo(address _address) view public returns (uint, string memory, string memory) {
        return (user_mapping[_address].time, user_mapping[_address].location, user_mapping[_address].position);
    }

    function countInfo() view public returns (uint) {
        return userAccounts.length;
    }

}
  • 1
    can you make your question a little more clear? What are you trying to do and where do you want to display the strings? – Sanjay S B Sep 4 at 8:05
  • I want to display it in a function(maybe the function names display), because I want to get all the location that input from the user, and then do some arrangement(if-else), finally send the results to the user. sorry, English is not my native language and I'm still new to the solidity. – lamigo6666 Sep 4 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.