forked from Communication-Systems-Group/solidity-examples
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathexample2.sol
More file actions
20 lines (16 loc) · 648 Bytes
/
Copy pathexample2.sol
File metadata and controls
20 lines (16 loc) · 648 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pragma solidity >0.4.10;
//the very second example
contract Example2 {
uint counter=0;
mapping (uint => string) stringList; //maps an integer to a string (creates an array)
function push(string memory info) public {
stringList[counter] = info; //saves the input string (info) into the list using the index "counter"
counter++; //increment the counter
}
function get(uint nr) public view returns (string memory) {
return stringList[nr]; //returns the string that is mapped to the index nr
}
function getCounter() public view returns (uint) {
return counter; //return the number of strings
}
}