structure assignment

How to write a structure with below member variables
string1-name
string2-address
unsigned integer- age

what did i done wrong in the code below
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16

struct{
    char *name[20];
    char *address[40];
    unsigned integer age;
 } employee

void main(void)
{
   employee thomas;
   thomas.name = "thomas Lim"
   thomas.address = "Singapore"
   thomas.age = 15

}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <iostream>
#include <string> // includes string object

using namespace std;


struct employee // employee up here
{
    string name; // use string
    string address; // use string
    unsigned int age; // integer data type is called "int" not "integer"
}; //add a semicolon


int main() // use int main() for no parameter main function not "void main(void)"
{
   employee thomas;
   thomas.name = "thomas Lim";
   thomas.address = "Singapore";
   thomas.age = 15;



   return 0; // main returns int, we return 0 by convention

}
Last edited on
1
2
3
char *name[20];
char *address[40];
unsigned integer age;

For strings, you do char name[20]. Or you could use the string class. In my opinion, I reckon the string class is noob friendly. You can even use the [] brackets like in an array.
if you dont know how much char your string can take , start by a const char * m_name;
Topic archived. No new replies allowed.