I embed CLIPS into C Language.
and have code:
main{
DATA_OBJECT factlist;
int end,i;
void *multifieldPtr;
char *tempPtr;
InitializeEnvironment();
Load("constructs.clp");
Reset();
GetFactList(&factlist,NULL);//send facts from clips to c application.
end=GetDOEnd(factlist);
printf("end=%d\n",end);
printf("Lengthis%d\n",GetDOLength(factlist));
multifieldPtr=GetValue(factlist);
printf("%d\n",end);
for (i = GetDOBegin(factlist); i <= end; i++){
printf("i=%d\n",i);
if (GetMFType(multifieldPtr,i) == FACT_ADDRESS){
tempPtr = ValueToString(GetMFValue(multifieldPtr,i));//have problems here
printf("%d\n",*tempPtr);//have problems here
}
else{printf("%d\n",GetMFType(multifieldPtr,i));
}
}
}
I know that GetMFType(muntifieldPtr,i)returns FACT_ADDRESS, I want to how to from the FACT_ADDRESS get the String value that represents the fact value and print the fact to the screen
Updating to the newest clips version(6.30).
#include "clips.h"
#define BUFFER_SIZE 1024
int main( int argc, char *argv[]){
DATA_OBJECT factlist;
char factBuffer[BUFFER_SIZE+1];
int end,i;
void *multifieldPtr;
void *theEnv;
theEnv = CreateEnvironment();
EnvBuild(theEnv, "(deffacts initial (colors red green blue) (animals cat dog chicken))");
EnvReset(theEnv);
EnvGetFactList(theEnv,&factlist,NULL);
if (GetType(factlist) == MULTIFIELD)
{
end = GetDOEnd(factlist);
multifieldPtr = GetValue(factlist);
for (i = GetDOBegin(factlist); i <= end; i++)
{
EnvGetFactPPForm(theEnv, factBuffer,BUFFER_SIZE,GetMFValue(multifieldPtr,i));
printf("%s\n",factBuffer);
}
}
return(-1);
}
You can compile with:
make -f makefile.lib
gcc <source file name> -L./ -lclips -lm -o <executable name>
Use the GetFactPPForm function. ValueToString should only be used in the type of the DATA_OBJECT is SYMBOL, STRING, or INSTANCE_NAME.
#define BUFFER_SIZE 1024
int main(
int argc,
char *argv[])
{
DATA_OBJECT factlist;
char factBuffer[BUFFER_SIZE+1];
int end,i;
void *multifieldPtr;
InitializeEnvironment();
Build("(deffacts initial (colors red green blue) (animals cat dog chicken))");
Reset();
GetFactList(&factlist,NULL);
if (GetType(factlist) == MULTIFIELD)
{
end = GetDOEnd(factlist);
multifieldPtr = GetValue(factlist);
for (i = GetDOBegin(factlist); i <= end; i++)
{
GetFactPPForm(factBuffer,BUFFER_SIZE,GetMFValue(multifieldPtr,i));
printf("%s\n",factBuffer);
}
}
return(-1);
}