Newsgroups: comp.lang.prolog
Path: cantaloupe.srv.cs.cmu.edu!bb3.andrew.cmu.edu!nntp.sei.cmu.edu!news.psc.edu!wink.radian.com!gatech!news.mathworks.com!rill.news.pipex.net!pipex!warwick!bris.ac.uk!not-for-mail
From: jw4505@harrier.fen.bris.ac.uk (J Warren)
Subject: Sicstus & C
X-Nntp-Posting-Host: harrier1.fen.bris.ac.uk
Message-ID: <E6xxIx.8vs@fsa.bris.ac.uk>
Sender: usenet@fsa.bris.ac.uk (Usenet)
Organization: University of Bristol, England
X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
Date: Wed, 12 Mar 1997 17:20:56 GMT
Lines: 57

Hi there,

I was hopping someone here could help me.  As part of a university project I have been given the task of calling
Sicstus prolog from C and hopefully then further C functions from within Sicstus.

What I was hoping was that someone could tell me where I can find more information than in the manual (hopefully
examples) or even offer advice on the code itself (I'll include the relevant sections below).

	Any advice greatlfully received as I have deadlines approaching fast,

		Julian Warren (jw4505@bris.ac.uk)

the C follows:

int c_control(int object, int controller, char **request_str) {  
  SP_pred_ref   pred;
  int      x, y, z, k;
  SP_qid   goal;
  SP_term_ref   p_ob, p_req, c_req, p_cc;
  char      *tempStr;
      
  p_ob  = SP_new_term_ref();
  p_cc  = SP_new_term_ref();
  p_req = SP_new_term_ref();
  c_req = SP_new_term_ref();
      
  pred  = SP_predicate("computer_control",3,"");
        
  SP_put_integer(p_ob, (long) object);
  SP_put_integer(p_cc, (long) controller);
  SP_put_variable(p_req);
  
  goal = SP_open_query(pred,p_ob,p_cc,p_req);
      
  #ifdef EBUG
   C_CONTROL_MESSAGE(-1, "c_control: Query opened.")
  #endif
      
  if(!(SP_next_solution(goal)))
   C_CONTROL_MESSAGE(3, "c_control: Failed to find solution to computer_control")
    
  y = SP_get_string(p_req, request_str);
   
  SP_close_query(goal);

  #ifdef EBUG
    printf("c_control: y=%d\n",y);
    printf("c_control: Output = %s\n", *request_str);
  #endif
  
  return(0);   /* Success = 0, Failure = (!0)  */
}

All this happens after I've initialised prolog and loaded in my file
(computer_control should take two integers and return a number of characters including some new lines).

This code only seems to fail when some other C functions are called.
