agg_mayur
Member level 3
Dear All,
Please tell me how to retun an array to a function. For e.g. i want to print Name
class office{
char name[4];
int emp;
public:
void set_name(char *n);
char get_name();
void set_emp(int e);
int get_emp();
};
void Office::set_name(char *n)
{
memcpy(&name,n,4); //Is it right
}
void Office::set_emp(int e)
{
emp = e;
}
char Office::get_name()
{
return *name; //How to return whole array to a function//wants modification
}
int Office::get_emp()
{
return emp;
}
int main()
{
char n[4] = "ABC";
Office o;
o.set_name;
o.set_emp(457);
cout << "Company Name is " << o.get_name();
cout << "\n"; cout << "\n";
cout << "No. of Employees are " << o.get_emp();
cout << "\n";
return 0;
}
Please tell me how to retun an array to a function. For e.g. i want to print Name
class office{
char name[4];
int emp;
public:
void set_name(char *n);
char get_name();
void set_emp(int e);
int get_emp();
};
void Office::set_name(char *n)
{
memcpy(&name,n,4); //Is it right
}
void Office::set_emp(int e)
{
emp = e;
}
char Office::get_name()
{
return *name; //How to return whole array to a function//wants modification
}
int Office::get_emp()
{
return emp;
}
int main()
{
char n[4] = "ABC";
Office o;
o.set_name;
o.set_emp(457);
cout << "Company Name is " << o.get_name();
cout << "\n"; cout << "\n";
cout << "No. of Employees are " << o.get_emp();
cout << "\n";
return 0;
}