/* * Project : Embedding SWI-Prolog in a C++ program. * * Author : Lens Stephane Ulg * Date : 10/2009 * * Sort a list. * */ #include #include #include using namespace std; int main(int argc, char *argv[]) { int i, res; string list[10]; /* Start Prolog engine */ PlEngine prolog(argv[0]); /* Get the 10 strings to sort */ cout << "Sort 10 strings\n" << endl; for (i = 0; i < 10; i++) { cout << "Next string to sort : "; cin >> list[i]; if (cin.fail()) return(1); } /* Define terms to use with Prolog */ PlTermv h(2); PlTail l(h[0]); /* Transform the list of strings to Prolog term */ for(i = 0; i < 10; i++) l.append(list[i].c_str()); l.close(); /* Call the predicate */ res = PlCall("msort", h); if (res != 1) { cerr << "Error with the predicate !" << endl; return(1); } /* Print the sorted list */ cout << "\nSorted List :\n\n" << (char *)h[1] << "\n" << endl; return 0; }