char* listToString(List* list) {
	if (list == NULL)
		return NULL;

	// allocate memory for string
	// assuming each variable will require 20 characters to represent it
	int size = getListSize(list);
	char* str = (char*) malloc(20 * size * sizeof(char));

	// empty the string
	str[0] = '\0';

	if (isEmpty(list))
		return NULL;

	// loop through the list and add each term to the string
	Node* n = list->head;
	while (n != NULL) {
		char* variable = VariableToString(n);

		// concatenate the "variable" string to the polynomial string
		strcat(str, variable);

		// add a space to separate terms
		strcat(str, " ");

		// go to the next node
		n = n->next;
	}

	return str;

}
示例#2
0
types::Function::ReturnValue sci_disp(types::typed_list &in, int _iRetCount, types::typed_list &out)
{
    types::typed_list::reverse_iterator it;

    if (in.empty())
    {
        Scierror(999, _("%s: Wrong number of input arguments: At least %d expected.\n"), "disp", 1);
        return types::Function::Error;
    }

    for (it = in.rbegin() ; it != in.rend() ; it++)
    {
        scilabForcedWriteW(L"\n");
        if (VariableToString(*it, SPACES_LIST) == types::Function::Error)
        {
            return types::Function::Error;
        }
    }

    return types::Function::OK;
}