I have a struct, how do I predefine data in this struct? example define life of struct 100?
I've tried dataplyer.vida = 100;
struct dataplayer
{
int vida;
int armadura;
int arma;
int level;
};
I have a struct, how do I predefine data in this struct? example define life of struct 100?
I've tried dataplyer.vida = 100;
struct dataplayer
{
int vida;
int armadura;
int arma;
int level;
};
The problem must be in another area of the code, apparently you seem to be correctly setting the attribute. So, I suppose your problem is another, but, answering the question, just use the "." (dot) to access the element you need and the assignment operator "=" to assign the value.
Of course, you need to create a "variable" to assign the actual value of a player to memory, in my case p1.
Here's an example:
#include <iostream>
using namespace std;
struct dataplayer { int vida; int armadura; int arma; int level; };
int main()
{
cout<<"definindo a vida \n";
//seu player
dataplayer p1;
p1.vida = 100;
cout << p1.vida;
return 0;
}
You can test this code here:
Note: It also was not clear to me, and I'm sleepy, if you encode in c or c ++, I recommend you choose one.