-
function call
this is my function protoype
void setString(const char *str);
i have to call it from another function
its purpose is to to set a variale called *theName
this is how i did it, but I am having problems
Code:
void Date::setDate(int m, int d, int y, const char *name)
{
theMonth = (m >= 1 && m <= 12) ? m : MM;
theYear = (y >= 0 && y <= MAX_YY) ? y : YY;
theDay = (d >= 1 && d <= 31) ? d : DD;
setString(*theName);
}
Is this right, i get confused with pointers...
-
I did it like this
Code:
void Date::setDate(int m, int d, int y, const char *name)
{
theMonth = (m >= 1 && m <= 12) ? m : MM;
theYear = (y >= 0 && y <= MAX_YY) ? y : YY;
theDay = (d >= 1 && d <= 31) ? d : DD;
setString(name);
}
I think it worked.
this is what the setString function looks like
Code:
void Date::setString(const char *str)
{
theName = new char[strlen(str) + 1];
assert(theName != 0);
strcpy(theName, str);
}