Ejemplo n.º 1
0
/**
 * @brief Sets the value of str to the value of other.
 * @param str the MyString to set
 * @param other the MyString to set from
 * RETURN VALUE:
 *  @return MYSTRING_SUCCESS on success, MYSTRING_ERROR on failure.
 */
MyStringRetVal myStringSetFromMyString(MyString *str, const MyString *other)
{
    if (other == NULL || str == NULL)
    {
        return MYSTRING_ERROR;
    }
    myStringFree(str);

    str = myStringClone(other);

    if (str == NULL)
    {
        return MYSTRING_ERROR;
    }
    return MYSTRING_SUCCESS;
}
Ejemplo n.º 2
0
/**
 * Create a string, clone it and compare them
 */
void test1()
{
    // for the sake of clarity, we don't check for errors in this demonstration

    // this function call allocates a number and sets it to 0
    MyString * s1 = myStringAlloc();
	MyStringRetVal rVal = myStringSetFromCString(s1, "Hello world?!?");
	MyString * s2 = myStringClone(s1);
	
	int res = myStringCompare(s1, s2);
	
	if (res != 0) 
	{
        exitBad(1);
    
    }

    myStringFree(s1);
    myStringFree(s2);
}