how to intialize char array with class method

i have a class employee which contain char array like showed in the code:
1
2
3
4
5
6
7
8
9

class employee
{
	char name[20];
	unsigned int salary;
public:
	void Init (??,signed int);
	void print();
};


how can i initialize the name array with the method Init without using strcpy?
Last edited on
Maybe something like this?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
class employee
{
	char name[20];
	unsigned int salary;
public:
	void Init (char* ename, unsigned int)
        {
                unsigned int i = 0;

                while(ename[i] != '\0')
                {
                        // Since the limit of the name is 20 characters
                        if(i < 20)
                        {
                                name[i] = ename[i];
                        }
                        
                        i++;
                }
        }
	void print();
};
Topic archived. No new replies allowed.