Thread: function call

  1. #1
    Registered User
    Join Date
    Feb 2002
    Posts
    20

    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...

  2. #2
    Registered User
    Join Date
    Feb 2002
    Posts
    20
    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);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  3. Troubleshooting Input Function
    By SiliconHobo in forum C Programming
    Replies: 14
    Last Post: 12-05-2007, 07:18 AM
  4. Replies: 28
    Last Post: 07-16-2006, 11:35 PM
  5. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM