return privat string form class function
please help me out...
As the subjekt tells; I have a privat char array in a class
and 2 public functions, one to Set Name and one to Get Name.
but, I don't know how to return a string/char array
I need to use the GetName function in the win32 wsprintf() fucntion, which is like the sprintf() as far as I know?!?
so...
how do i return a char array from a function?
and how do I use the function return in wsprintf()???
here is my code...
Code:
class Fighter
{
public:
void SetName(char NameSet[]);
char* GetName();
private:
char Name[];
};
void Fighter::SetName(char NameSet[])
{
strcpy(Name, NameSet);
}
char* Fighter::GetName()
{
return Name;
}
//somewere in winprog
int szBuffer[100]
wsprintf (szBuffer, TEXT ("%s"), User.GetName() );
MessageBox (NULL, szBuffer , "Name", 0 + MB_DEFBUTTON1 + MB_ICONASTERISK);
my problem is realy more c++ then win32 I think...
thats all... please reply :)
I can attach my full projekt if you ask!
this me that stratet this thread
Thanks for your help!!! :) :) :)
This is how I got it to work:
Code:
class Fighter
{
public:
void SetName(const char * NameSet);
char * GetName();
private:
char Name[100];
};
void Fighter::SetName(const char * NameSet)
{
strncpy(Name, NameSet, 100);
}
char* Fighter::GetName()
{
char * ret = new char[100];
memcpy(ret, Name, 100);
return ret;
}
//somewere in winprog
char szBuffer[100]
wsprintf (szBuffer, TEXT ("%s"), User.GetName() );
MessageBox (NULL, szBuffer , "Name", 0 + MB_DEFBUTTON1 + MB_ICONASTERISK);
-GuruN