Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cinterf.h>
- #include <stdio.h>
- int main()
- {
- // 1) Create a 'VarString' object called 'queryValue'
- XSB_StrDefine(queryValue);
- // 2) Initialize XSB
- if(xsb_init_string("path/to/XSB"))
- {
- printf("++XSB failed to initialize with error: %s\n", xsb_get_init_error_message());
- exit(-1);
- }
- else
- {
- // 3) Load XSB script with defined terms such as 'f(a,b,c)' 'f(1,2,3)' etc.
- xsb_command_string("consult('./script.P').");
- // 4) Query XSB with 'f(X,Y,Z)' and pass first result of query into 'queryValue' variable declared above
- // with each value of the result seperated by ',''s. Ex. 'a,b,c' for 'X=a, Y=b, Z=c', '1,2,3' for 'X=1, Y=2, Z=3' etc.
- // Returns XSB_SUCCESS if query returns a result
- if(xsb_query_string_string("f(X,Y,Z).", &queryValue, ",") == XSB_SUCCESS)
- {
- // Keep passing query results into 'queryValue' until there are no more values from the query
- while(xsb_next_string(&queryValue, ",") == XSB_SUCCESS)
- {
- // Print result of query
- printf("Query result: %s\n", queryValue.string);
- }
- }
- // Terminate XSB
- xsb_close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement